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:
@@ -50,7 +50,7 @@ def extract_blinfo(path: pathlib.Path) -> dict:
|
|||||||
|
|
||||||
source = None
|
source = None
|
||||||
# get last component of path
|
# get last component of path
|
||||||
addon_name = path.parts[-1]
|
addon_name = path.name
|
||||||
|
|
||||||
if path.is_dir():
|
if path.is_dir():
|
||||||
with open(path / '__init__.py', 'r') as f:
|
with open(path / '__init__.py', 'r') as f:
|
||||||
@@ -87,7 +87,7 @@ def make_repo(repopath: pathlib.Path):
|
|||||||
|
|
||||||
for addon_path in repopath.iterdir():
|
for addon_path in repopath.iterdir():
|
||||||
package_datum = {}
|
package_datum = {}
|
||||||
addon = addon_path.parts[-1]
|
addon = addon_path.name
|
||||||
|
|
||||||
try:
|
try:
|
||||||
bl_info = extract_blinfo(addon_path)
|
bl_info = extract_blinfo(addon_path)
|
||||||
|
@@ -9,14 +9,14 @@ import blenderpack
|
|||||||
class test_blenderpack_make_repo(unittest.TestCase):
|
class test_blenderpack_make_repo(unittest.TestCase):
|
||||||
|
|
||||||
helper_path = Path('tests', 'test_helpers')
|
helper_path = Path('tests', 'test_helpers')
|
||||||
addon_path = Path(helper_path, 'addons')
|
addon_path = helper_path / 'addons'
|
||||||
|
|
||||||
def test_extract_blinfo_from_nonexistent(self):
|
def test_extract_blinfo_from_nonexistent(self):
|
||||||
test_file = 'file_that_doesnt_exist'
|
test_file = 'file_that_doesnt_exist'
|
||||||
self.assertRaises(
|
self.assertRaises(
|
||||||
FileNotFoundError,
|
FileNotFoundError,
|
||||||
blenderpack.extract_blinfo,
|
blenderpack.extract_blinfo,
|
||||||
Path(self.addon_path, test_file)
|
self.addon_path / test_file
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_extract_blinfo_from_nonaddon(self):
|
def test_extract_blinfo_from_nonaddon(self):
|
||||||
@@ -24,12 +24,12 @@ class test_blenderpack_make_repo(unittest.TestCase):
|
|||||||
self.assertRaises(
|
self.assertRaises(
|
||||||
blenderpack.BadAddon,
|
blenderpack.BadAddon,
|
||||||
blenderpack.extract_blinfo,
|
blenderpack.extract_blinfo,
|
||||||
Path(self.addon_path, test_file)
|
self.addon_path / test_file
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_make_repo_valid(self):
|
def test_make_repo_valid(self):
|
||||||
blenderpack.make_repo(Path(self.helper_path, 'addons'))
|
blenderpack.make_repo(self.helper_path / 'addons')
|
||||||
repojson = Path(self.helper_path, 'addons', 'repo.json')
|
repojson = self.helper_path / 'addons' / 'repo.json'
|
||||||
|
|
||||||
self.assertTrue(repojson.is_file())
|
self.assertTrue(repojson.is_file())
|
||||||
with repojson.open('r') as f:
|
with repojson.open('r') as f:
|
||||||
@@ -39,7 +39,7 @@ class test_blenderpack_make_repo(unittest.TestCase):
|
|||||||
self.fail('unfinished test')
|
self.fail('unfinished test')
|
||||||
|
|
||||||
def test_make_repo_from_nonexistent(self):
|
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')
|
self.fail('unfinished test')
|
||||||
|
|
||||||
|
|
||||||
@@ -52,7 +52,7 @@ bl_info_tests = {
|
|||||||
|
|
||||||
def generate_test(test_file):
|
def generate_test(test_file):
|
||||||
def test(self):
|
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:
|
with (self.helper_path / (test_file + '_output')).open() as f:
|
||||||
expectation = f.read()
|
expectation = f.read()
|
||||||
self.assertEqual(expectation, reality)
|
self.assertEqual(expectation, reality)
|
||||||
|
Reference in New Issue
Block a user