Get all tests for make_repo.py passing

This commit is contained in:
gandalf3
2017-07-02 16:55:17 -07:00
parent 8baacc366b
commit 9f0ff11421
3 changed files with 202 additions and 32 deletions

View File

@@ -18,15 +18,14 @@ class BadAddon(Exception):
def iter_addons(path: Path) -> (Path, dict):
"""
Generator, yields (path, bl_info) of blender addons in `path` (non recursive).
Generator, yields (path, bl_info) of blender addons in `path`.
"""
pass
# for item in addons_dir.iterdir():
# base = item.name
#
# yield (base, fname, '.zip')
# else:
# yield (base, item.path, '.py')
for item in path.iterdir():
try:
yield(item, extract_blinfo(item))
except BadAddon as err:
log.debug("Skipping '{}': {}".format(item.name, err))
def parse_blinfo(source: str) -> dict:
"""Parse a python file and return its bl_info dict, if there is one (else return None)"""
@@ -80,16 +79,19 @@ def extract_blinfo(item: Path) -> dict:
for fname in z.namelist():
# TODO: zips with multiple bl_infos might be a problem,
# not sure how such cases should be handled (if at all)
# for now we just break after the first one
if fname.endswith('__init__.py'):
try:
blinfo = parse_blinfo(z.read(fname))
break
except BadAddon:
continue
raise BadAddon("Zipfile '%s' doesn't contain any readable bl_info dict" % item)
if blinfo is None:
raise BadAddon("Zipfile '%s' doesn't contain a readable bl_info dict" % item)
except zipfile.BadZipFile:
# Assume file is
# If it's not a valid zip, assume file is just a normal file
# TODO: this probably blows up inelegantly on corrupted zips
with item.open() as f:
blinfo = parse_blinfo(f.read())
@@ -101,24 +103,17 @@ def extract_blinfo(item: Path) -> dict:
def make_repo(repopath: Path):
"""Make repo.json for files in directory 'repopath'"""
def make_repo(path: Path):
"""Make repo.json for files in directory 'path'"""
repo_data = {}
package_data = []
if not repopath.is_dir():
raise FileNotFoundError(repopath)
if not path.is_dir():
raise FileNotFoundError(path)
for addon_path in repopath.iterdir():
for addon, bl_info in iter_addons(path):
package_datum = {}
addon = addon_path.name
try:
bl_info = extract_blinfo(addon_path)
except BadAddon as err:
log.warning('Could not extract bl_info from {}: {}'.format(addon_path, err))
continue
if not REQUIRED_KEYS.issubset(set(bl_info)):
log.warning(

View File

@@ -0,0 +1,176 @@
{
"packages": [
{
"bl_info": {
"author": "Multiple Authors",
"blender": [
2,
76,
0
],
"category": "Add Curve",
"description": "Add extra curve object types",
"location": "View3D > Add > Curve > Extra Objects",
"name": "Extra Objects",
"version": [
0,
1,
2
],
"warning": "",
"wiki_url": "https://wiki.blender.org/index.php/Extensions:2.6/Py/Scripts/Curve/Curve_Objects"
},
"type": "addon"
},
{
"bl_info": {
"author": "testscreenings, PKHG, TrumanBlending",
"blender": [
2,
59,
0
],
"category": "Add Curve",
"description": "Adds generated ivy to a mesh object starting at the 3D cursor",
"location": "View3D > Add > Curve",
"version": [
0,
1,
2
],
"warning": "",
"wiki_url": "https://wiki.blender.org/index.php/Extensions:2.6/Py/Scripts/Curve/Ivy_Gen"
},
"type": "addon"
},
{
"bl_info": {
"author": "testscreenings, PKHG, TrumanBlending",
"blender": [
2,
59,
0
],
"category": "Add Curve",
"description": "Adds generated ivy to a mesh object starting at the 3D cursor",
"location": "View3D > Add > Curve",
"version": [
0,
1,
2
],
"warning": "",
"wiki_url": "https://wiki.blender.org/index.php/Extensions:2.6/Py/Scripts/Curve/Ivy_Gen"
},
"type": "addon"
},
{
"bl_info": {
"author": "Multiple Authors",
"blender": [
2,
76,
0
],
"category": "Add Curve",
"description": "Add extra curve object types",
"location": "View3D > Add > Curve > Extra Objects",
"name": "Extra Objects",
"version": [
0,
1,
2
],
"warning": "",
"wiki_url": "https://wiki.blender.org/index.php/Extensions:2.6/Py/Scripts/Curve/Curve_Objects"
},
"type": "addon"
},
{
"bl_info": {
"author": "testscreenings, PKHG, TrumanBlending",
"blender": [
2,
59,
0
],
"category": "Add Curve",
"description": "Adds generated ivy to a mesh object starting at the 3D cursor",
"location": "View3D > Add > Curve",
"version": [
0,
1,
2
],
"warning": "",
"wiki_url": "https://wiki.blender.org/index.php/Extensions:2.6/Py/Scripts/Curve/Ivy_Gen"
},
"type": "addon"
},
{
"bl_info": {
"author": "testscreenings, PKHG, TrumanBlending",
"blender": [
2,
59,
0
],
"category": "Add Curve",
"description": "Adds generated ivy to a mesh object starting at the 3D cursor",
"location": "View3D > Add > Curve",
"version": [
0,
1,
2
],
"warning": "",
"wiki_url": "https://wiki.blender.org/index.php/Extensions:2.6/Py/Scripts/Curve/Ivy_Gen"
},
"type": "addon"
},
{
"bl_info": {
"author": "Multiple Authors",
"blender": [
2,
76,
0
],
"category": "Add Curve",
"description": "Add extra curve object types",
"location": "View3D > Add > Curve > Extra Objects",
"name": "Extra Objects",
"version": [
0,
1,
2
],
"warning": "",
"wiki_url": "https://wiki.blender.org/index.php/Extensions:2.6/Py/Scripts/Curve/Curve_Objects"
},
"type": "addon"
},
{
"bl_info": {
"author": "Multiple Authors",
"blender": [
2,
76,
0
],
"category": "Add Curve",
"description": "Add extra curve object types",
"location": "View3D > Add > Curve > Extra Objects",
"name": "Extra Objects",
"version": [
0,
1,
2
],
"warning": "",
"wiki_url": "https://wiki.blender.org/index.php/Extensions:2.6/Py/Scripts/Curve/Curve_Objects"
},
"type": "addon"
}
]
}

View File

@@ -26,18 +26,20 @@ class test_make_repo(unittest.TestCase):
def test_make_repo_valid(self):
make_repo.make_repo(self.helper_path / 'addons')
repojson = Path.cwd() / 'repo.json'
reference_repojson = self.helper_path / 'repo.json'
try:
with repojson.open('r') as f:
json.loads(f.read())
with repojson.open('r') as repolist_f:
with reference_repojson.open('r') as ref_repolist_f:
repolist = json.loads(repolist_f.read())
ref_repolist = json.loads(ref_repolist_f.read())
self.assertEqual(repolist, ref_repolist)
finally:
repojson.unlink()
self.fail('unfinished test')
def test_make_repo_from_nonexistent(self):
make_repo.make_repo(self.helper_path / 'addons')
self.fail('unfinished test')
with self.assertRaises(FileNotFoundError):
make_repo.make_repo(Path('in_a_galaxy_far_far_away'))
# addons which should contain bl_infos
yes_blinfo = [
@@ -60,11 +62,8 @@ def generate_good_blinfo_test(test_file: Path):
def generate_bad_blinfo_test(test_file: Path):
def test(self):
self.assertRaises(
make_repo.BadAddon,
make_repo.extract_blinfo,
test_file
)
with self.assertRaises(make_repo.BadAddon):
make_repo.extract_blinfo(test_file)
return test
# Add test method retur