Get all tests for make_repo.py passing
This commit is contained in:
37
make_repo.py
37
make_repo.py
@@ -18,15 +18,14 @@ class BadAddon(Exception):
|
|||||||
|
|
||||||
def iter_addons(path: Path) -> (Path, dict):
|
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
|
pass
|
||||||
# for item in addons_dir.iterdir():
|
for item in path.iterdir():
|
||||||
# base = item.name
|
try:
|
||||||
#
|
yield(item, extract_blinfo(item))
|
||||||
# yield (base, fname, '.zip')
|
except BadAddon as err:
|
||||||
# else:
|
log.debug("Skipping '{}': {}".format(item.name, err))
|
||||||
# yield (base, item.path, '.py')
|
|
||||||
|
|
||||||
def parse_blinfo(source: str) -> dict:
|
def parse_blinfo(source: str) -> dict:
|
||||||
"""Parse a python file and return its bl_info dict, if there is one (else return None)"""
|
"""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():
|
for fname in z.namelist():
|
||||||
# TODO: zips with multiple bl_infos might be a problem,
|
# TODO: zips with multiple bl_infos might be a problem,
|
||||||
# not sure how such cases should be handled (if at all)
|
# 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'):
|
if fname.endswith('__init__.py'):
|
||||||
try:
|
try:
|
||||||
blinfo = parse_blinfo(z.read(fname))
|
blinfo = parse_blinfo(z.read(fname))
|
||||||
break
|
break
|
||||||
except BadAddon:
|
except BadAddon:
|
||||||
continue
|
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:
|
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:
|
with item.open() as f:
|
||||||
blinfo = parse_blinfo(f.read())
|
blinfo = parse_blinfo(f.read())
|
||||||
|
|
||||||
@@ -101,24 +103,17 @@ def extract_blinfo(item: Path) -> dict:
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
def make_repo(repopath: Path):
|
def make_repo(path: Path):
|
||||||
"""Make repo.json for files in directory 'repopath'"""
|
"""Make repo.json for files in directory 'path'"""
|
||||||
|
|
||||||
repo_data = {}
|
repo_data = {}
|
||||||
package_data = []
|
package_data = []
|
||||||
|
|
||||||
if not repopath.is_dir():
|
if not path.is_dir():
|
||||||
raise FileNotFoundError(repopath)
|
raise FileNotFoundError(path)
|
||||||
|
|
||||||
for addon_path in repopath.iterdir():
|
for addon, bl_info in iter_addons(path):
|
||||||
package_datum = {}
|
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)):
|
if not REQUIRED_KEYS.issubset(set(bl_info)):
|
||||||
log.warning(
|
log.warning(
|
||||||
|
176
tests/test_helpers/repo.json
Normal file
176
tests/test_helpers/repo.json
Normal 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"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
@@ -26,18 +26,20 @@ class test_make_repo(unittest.TestCase):
|
|||||||
def test_make_repo_valid(self):
|
def test_make_repo_valid(self):
|
||||||
make_repo.make_repo(self.helper_path / 'addons')
|
make_repo.make_repo(self.helper_path / 'addons')
|
||||||
repojson = Path.cwd() / 'repo.json'
|
repojson = Path.cwd() / 'repo.json'
|
||||||
|
reference_repojson = self.helper_path / 'repo.json'
|
||||||
|
|
||||||
try:
|
try:
|
||||||
with repojson.open('r') as f:
|
with repojson.open('r') as repolist_f:
|
||||||
json.loads(f.read())
|
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:
|
finally:
|
||||||
repojson.unlink()
|
repojson.unlink()
|
||||||
|
|
||||||
self.fail('unfinished test')
|
|
||||||
|
|
||||||
def test_make_repo_from_nonexistent(self):
|
def test_make_repo_from_nonexistent(self):
|
||||||
make_repo.make_repo(self.helper_path / 'addons')
|
with self.assertRaises(FileNotFoundError):
|
||||||
self.fail('unfinished test')
|
make_repo.make_repo(Path('in_a_galaxy_far_far_away'))
|
||||||
|
|
||||||
# addons which should contain bl_infos
|
# addons which should contain bl_infos
|
||||||
yes_blinfo = [
|
yes_blinfo = [
|
||||||
@@ -60,11 +62,8 @@ def generate_good_blinfo_test(test_file: Path):
|
|||||||
|
|
||||||
def generate_bad_blinfo_test(test_file: Path):
|
def generate_bad_blinfo_test(test_file: Path):
|
||||||
def test(self):
|
def test(self):
|
||||||
self.assertRaises(
|
with self.assertRaises(make_repo.BadAddon):
|
||||||
make_repo.BadAddon,
|
make_repo.extract_blinfo(test_file)
|
||||||
make_repo.extract_blinfo,
|
|
||||||
test_file
|
|
||||||
)
|
|
||||||
return test
|
return test
|
||||||
|
|
||||||
# Add test method retur
|
# Add test method retur
|
||||||
|
Reference in New Issue
Block a user