Cleanup: take advantage of pathlib

* Use / syntax for concating pathlib paths in tests
* Use .name for getting last component of pathlib path
This commit is contained in:
gandalf3
2017-06-29 02:11:43 -07:00
parent 172353bbbb
commit 5a0aba8a56
2 changed files with 9 additions and 9 deletions

View File

@@ -50,7 +50,7 @@ def extract_blinfo(path: pathlib.Path) -> dict:
source = None
# get last component of path
addon_name = path.parts[-1]
addon_name = path.name
if path.is_dir():
with open(path / '__init__.py', 'r') as f:
@@ -87,7 +87,7 @@ def make_repo(repopath: pathlib.Path):
for addon_path in repopath.iterdir():
package_datum = {}
addon = addon_path.parts[-1]
addon = addon_path.name
try:
bl_info = extract_blinfo(addon_path)

View File

@@ -9,14 +9,14 @@ import blenderpack
class test_blenderpack_make_repo(unittest.TestCase):
helper_path = Path('tests', 'test_helpers')
addon_path = Path(helper_path, 'addons')
addon_path = helper_path / 'addons'
def test_extract_blinfo_from_nonexistent(self):
test_file = 'file_that_doesnt_exist'
self.assertRaises(
FileNotFoundError,
blenderpack.extract_blinfo,
Path(self.addon_path, test_file)
self.addon_path / test_file
)
def test_extract_blinfo_from_nonaddon(self):
@@ -24,12 +24,12 @@ class test_blenderpack_make_repo(unittest.TestCase):
self.assertRaises(
blenderpack.BadAddon,
blenderpack.extract_blinfo,
Path(self.addon_path, test_file)
self.addon_path / test_file
)
def test_make_repo_valid(self):
blenderpack.make_repo(Path(self.helper_path, 'addons'))
repojson = Path(self.helper_path, 'addons', 'repo.json')
blenderpack.make_repo(self.helper_path / 'addons')
repojson = self.helper_path / 'addons' / 'repo.json'
self.assertTrue(repojson.is_file())
with repojson.open('r') as f:
@@ -39,7 +39,7 @@ class test_blenderpack_make_repo(unittest.TestCase):
self.fail('unfinished test')
def test_make_repo_from_nonexistent(self):
blenderpack.make_repo(Path(self.helper_path, 'addons'))
blenderpack.make_repo(self.helper_path / 'addons')
self.fail('unfinished test')
@@ -52,7 +52,7 @@ bl_info_tests = {
def generate_test(test_file):
def test(self):
reality = str(blenderpack.extract_blinfo(Path(self.addon_path, test_file)))
reality = str(blenderpack.extract_blinfo(self.addon_path / test_file))
with (self.helper_path / (test_file + '_output')).open() as f:
expectation = f.read()
self.assertEqual(expectation, reality)