| 1 | #!/usr/bin/env python |
|---|
| 2 | # -*- coding: utf-8 -*- |
|---|
| 3 | |
|---|
| 4 | # Copyright (C) 2009 Adriano Monteiro Marques. |
|---|
| 5 | # |
|---|
| 6 | # Author: Bartosz SKOWRON <getxsick at gmail dot com> |
|---|
| 7 | # |
|---|
| 8 | # This library is free software; you can redistribute it and/or modify |
|---|
| 9 | # it under the terms of the GNU Lesser General Public License as published |
|---|
| 10 | # by the Free Software Foundation; either version 2.1 of the License, or |
|---|
| 11 | # (at your option) any later version. |
|---|
| 12 | # |
|---|
| 13 | # This library is distributed in the hope that it will be useful, but |
|---|
| 14 | # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
|---|
| 15 | # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public |
|---|
| 16 | # License for more details. |
|---|
| 17 | # |
|---|
| 18 | # You should have received a copy of the GNU Lesser General Public License |
|---|
| 19 | # along with this library; if not, write to the Free Software Foundation, |
|---|
| 20 | # Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|---|
| 21 | |
|---|
| 22 | import os |
|---|
| 23 | import sys |
|---|
| 24 | import shutil |
|---|
| 25 | import tempfile |
|---|
| 26 | |
|---|
| 27 | old_expanduser = os.path.expanduser |
|---|
| 28 | |
|---|
| 29 | class TestUMPAInitialization(object): |
|---|
| 30 | def setup_class(cls): |
|---|
| 31 | # overwrite expanduser to use our temporary directory |
|---|
| 32 | # NOTE: this test has to be run as a first because of this! |
|---|
| 33 | def expanduser(path): |
|---|
| 34 | return cls.tmp_dir |
|---|
| 35 | cls.tmp_dir = tempfile.mkdtemp() |
|---|
| 36 | #cls.old_expanduser = os.path.expanduser |
|---|
| 37 | os.path.expanduser = expanduser |
|---|
| 38 | import umpa |
|---|
| 39 | # dirty hack to get possibility of reload module later |
|---|
| 40 | globals()[umpa.__name__] = umpa |
|---|
| 41 | |
|---|
| 42 | def teardown_class(cls): |
|---|
| 43 | shutil.rmtree(cls.tmp_dir) |
|---|
| 44 | os.path.expanduser = old_expanduser |
|---|
| 45 | reload(umpa) |
|---|
| 46 | |
|---|
| 47 | def test_paths(self): |
|---|
| 48 | def path_exist(path): |
|---|
| 49 | assert os.path.isdir(path) |
|---|
| 50 | assert os.path.isfile(os.path.join(path, '__init__.py')) |
|---|
| 51 | |
|---|
| 52 | home = os.path.join(os.path.expanduser('~'), '.umpa') |
|---|
| 53 | dirs = ('umpa_plugins', |
|---|
| 54 | os.path.join('umpa_plugins', 'protocols'), |
|---|
| 55 | os.path.join('umpa_plugins', 'extensions'), |
|---|
| 56 | ) |
|---|
| 57 | path_list = [ os.path.join(home, p) for p in dirs ] |
|---|
| 58 | |
|---|
| 59 | for path in path_list: |
|---|
| 60 | yield path_exist, path |
|---|
| 61 | |
|---|
| 62 | def test_syspath(self): |
|---|
| 63 | home = os.path.join(os.path.expanduser('~'), '.umpa') |
|---|
| 64 | assert home in sys.path |
|---|
| 65 | assert sys.path.index(home) == 0 |
|---|
| 66 | |
|---|
| 67 | def test_reconstruct_broken_directory(self): |
|---|
| 68 | home = os.path.join(os.path.expanduser('~'), '.umpa') |
|---|
| 69 | for dir in os.listdir(home): |
|---|
| 70 | shutil.rmtree(os.path.join(home,dir)) |
|---|
| 71 | reload(umpa) |
|---|
| 72 | self.test_paths() |
|---|