Split repo generation functionality out of blenderpack.py
Moved repo.json generation to make_repo.py Package/addon parsing is getting a bit messy, this can be cleaned up when we have a clearer idea of what a package is. For now just make it work.
This commit is contained in:
Binary file not shown.
BIN
tests/test_helpers/addons/dir_invalid_addon.zip
Normal file
BIN
tests/test_helpers/addons/dir_invalid_addon.zip
Normal file
Binary file not shown.
12
tests/test_helpers/addons/dir_invalid_addon/__init__.py
Normal file
12
tests/test_helpers/addons/dir_invalid_addon/__init__.py
Normal file
@@ -0,0 +1,12 @@
|
||||
bl_info = {
|
||||
"author": "testscreenings, PKHG, TrumanBlending",
|
||||
"version": (0, 1, 2),
|
||||
"blender": (2, 59, 0),
|
||||
"location": "View3D > Add > Curve",
|
||||
"description": "Adds generated ivy to a mesh object starting "
|
||||
"at the 3D cursor",
|
||||
"warning": "",
|
||||
"wiki_url": "https://wiki.blender.org/index.php/Extensions:2.6/Py/"
|
||||
"Scripts/Curve/Ivy_Gen",
|
||||
"category": "Add Curve",
|
||||
}
|
Binary file not shown.
BIN
tests/test_helpers/addons/invalid_addon.zip
Normal file
BIN
tests/test_helpers/addons/invalid_addon.zip
Normal file
Binary file not shown.
BIN
tests/test_helpers/addons/nonaddon.zip
Normal file
BIN
tests/test_helpers/addons/nonaddon.zip
Normal file
Binary file not shown.
@@ -18,21 +18,36 @@
|
||||
|
||||
# <pep8-80 compliant>
|
||||
|
||||
# bl_info = {
|
||||
# "name": "IvyGen",
|
||||
# "author": "testscreenings, PKHG, TrumanBlending",
|
||||
# "version": (0, 1, 2),
|
||||
# "blender": (2, 59, 0),
|
||||
# "location": "View3D > Add > Curve",
|
||||
# "description": "Adds generated ivy to a mesh object starting "
|
||||
# "at the 3D cursor",
|
||||
# "warning": "",
|
||||
# "wiki_url": "https://wiki.blender.org/index.php/Extensions:2.6/Py/"
|
||||
# "Scripts/Curve/Ivy_Gen",
|
||||
# "category": "Add Curve",
|
||||
# }
|
||||
|
||||
# just use one blinfo for all addons to simplify testing
|
||||
bl_info = {
|
||||
"name": "IvyGen",
|
||||
"author": "testscreenings, PKHG, TrumanBlending",
|
||||
"name": "Extra Objects",
|
||||
"author": "Multiple Authors",
|
||||
"version": (0, 1, 2),
|
||||
"blender": (2, 59, 0),
|
||||
"location": "View3D > Add > Curve",
|
||||
"description": "Adds generated ivy to a mesh object starting "
|
||||
"at the 3D cursor",
|
||||
"blender": (2, 76, 0),
|
||||
"location": "View3D > Add > Curve > Extra Objects",
|
||||
"description": "Add extra curve object types",
|
||||
"warning": "",
|
||||
"wiki_url": "https://wiki.blender.org/index.php/Extensions:2.6/Py/"
|
||||
"Scripts/Curve/Ivy_Gen",
|
||||
"category": "Add Curve",
|
||||
"Scripts/Curve/Curve_Objects",
|
||||
"category": "Add Curve"
|
||||
}
|
||||
|
||||
|
||||
|
||||
import bpy
|
||||
from bpy.props import (
|
||||
FloatProperty,
|
BIN
tests/test_helpers/addons/singlefile_addon.zip
Normal file
BIN
tests/test_helpers/addons/singlefile_addon.zip
Normal file
Binary file not shown.
Binary file not shown.
@@ -1 +0,0 @@
|
||||
{'name': 'Extra Objects', 'author': 'Multiple Authors', 'version': (0, 1, 2), 'blender': (2, 76, 0), 'location': 'View3D > Add > Curve > Extra Objects', 'description': 'Add extra curve object types', 'warning': '', 'wiki_url': 'https://wiki.blender.org/index.php/Extensions:2.6/Py/Scripts/Curve/Curve_Objects', 'category': 'Add Curve'}
|
13
tests/test_helpers/expected_blinfo
Normal file
13
tests/test_helpers/expected_blinfo
Normal file
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"name": "Extra Objects",
|
||||
"author": "Multiple Authors",
|
||||
"version": (0, 1, 2),
|
||||
"blender": (2, 76, 0),
|
||||
"location": "View3D > Add > Curve > Extra Objects",
|
||||
"description": "Add extra curve object types",
|
||||
"warning": "",
|
||||
"wiki_url": "https://wiki.blender.org/index.php/Extensions:2.6/Py/"
|
||||
"Scripts/Curve/Curve_Objects",
|
||||
"category": "Add Curve"
|
||||
}
|
||||
|
@@ -1 +0,0 @@
|
||||
{'name': 'IvyGen', 'author': 'testscreenings, PKHG, TrumanBlending', 'version': (0, 1, 2), 'blender': (2, 59, 0), 'location': 'View3D > Add > Curve', 'description': 'Adds generated ivy to a mesh object starting at the 3D cursor', 'warning': '', 'wiki_url': 'https://wiki.blender.org/index.php/Extensions:2.6/Py/Scripts/Curve/Ivy_Gen', 'category': 'Add Curve'}
|
@@ -1 +0,0 @@
|
||||
{'name': 'Extra Objects', 'author': 'Multiple Authors', 'version': (0, 1, 2), 'blender': (2, 76, 0), 'location': 'View3D > Add > Curve > Extra Objects', 'description': 'Add extra curve object types', 'warning': '', 'wiki_url': 'https://wiki.blender.org/index.php/Extensions:2.6/Py/Scripts/Curve/Curve_Objects', 'category': 'Add Curve'}
|
@@ -2,11 +2,15 @@
|
||||
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
import os
|
||||
import logging
|
||||
import ast
|
||||
import json
|
||||
import blenderpack
|
||||
import make_repo
|
||||
|
||||
class test_blenderpack_make_repo(unittest.TestCase):
|
||||
logging.basicConfig(level=logging.DEBUG,
|
||||
format='%(levelname)8s: %(message)s')
|
||||
|
||||
class test_make_repo(unittest.TestCase):
|
||||
|
||||
helper_path = Path('tests', 'test_helpers')
|
||||
addon_path = helper_path / 'addons'
|
||||
@@ -15,20 +19,12 @@ class test_blenderpack_make_repo(unittest.TestCase):
|
||||
test_file = 'file_that_doesnt_exist'
|
||||
self.assertRaises(
|
||||
FileNotFoundError,
|
||||
blenderpack.extract_blinfo,
|
||||
self.addon_path / test_file
|
||||
)
|
||||
|
||||
def test_extract_blinfo_from_nonaddon(self):
|
||||
test_file = 'not_an_addon.py'
|
||||
self.assertRaises(
|
||||
blenderpack.BadAddon,
|
||||
blenderpack.extract_blinfo,
|
||||
make_repo.extract_blinfo,
|
||||
self.addon_path / test_file
|
||||
)
|
||||
|
||||
def test_make_repo_valid(self):
|
||||
blenderpack.make_repo(self.helper_path / 'addons')
|
||||
make_repo.make_repo(self.helper_path / 'addons')
|
||||
repojson = Path.cwd() / 'repo.json'
|
||||
|
||||
try:
|
||||
@@ -40,26 +36,46 @@ class test_blenderpack_make_repo(unittest.TestCase):
|
||||
self.fail('unfinished test')
|
||||
|
||||
def test_make_repo_from_nonexistent(self):
|
||||
blenderpack.make_repo(self.helper_path / 'addons')
|
||||
make_repo.make_repo(self.helper_path / 'addons')
|
||||
self.fail('unfinished test')
|
||||
|
||||
# addons which should contain bl_infos
|
||||
yes_blinfo = [
|
||||
f for f in test_make_repo.addon_path.iterdir()
|
||||
if not f.match('*nonaddon*') and not f.match('*invalid_addon*')
|
||||
]
|
||||
# addons which should throw BadAddon because they have no blinfo
|
||||
no_blinfo = [
|
||||
f for f in test_make_repo.addon_path.iterdir()
|
||||
if f.match('*nonaddon*')
|
||||
]
|
||||
|
||||
# testname: filename
|
||||
bl_info_tests = {
|
||||
'test_extract_blinfo_from_file': 'real_addon.py',
|
||||
'test_extract_blinfo_from_zip': 'zipped_addon.zip',
|
||||
'test_extract_blinfo_from_dir': 'dir_addon',
|
||||
}
|
||||
|
||||
def generate_test(test_file):
|
||||
def generate_good_blinfo_test(test_file: Path):
|
||||
def test(self):
|
||||
reality = str(blenderpack.extract_blinfo(self.addon_path / test_file))
|
||||
with (self.helper_path / (test_file + '_output')).open() as f:
|
||||
expectation = f.read()
|
||||
reality = make_repo.extract_blinfo(test_file)
|
||||
with (self.helper_path / 'expected_blinfo').open("r") as f:
|
||||
expectation = ast.literal_eval(f.read())
|
||||
self.assertEqual(expectation, reality)
|
||||
return test
|
||||
|
||||
for name, param in bl_info_tests.items():
|
||||
test_func = generate_test(param)
|
||||
setattr(test_blenderpack_make_repo, 'test_{}'.format(name), test_func)
|
||||
def generate_bad_blinfo_test(test_file: Path):
|
||||
def test(self):
|
||||
self.assertRaises(
|
||||
make_repo.BadAddon,
|
||||
make_repo.extract_blinfo,
|
||||
test_file
|
||||
)
|
||||
return test
|
||||
|
||||
# Add test method retur
|
||||
def add_generated_tests(test_generator, params, destclass):
|
||||
"""
|
||||
Add a test method (as returned by 'test_generator') to destclass for every param
|
||||
"""
|
||||
for param in params:
|
||||
test_func = test_generator(param)
|
||||
setattr(destclass, 'test_{}'.format(param), test_func)
|
||||
|
||||
add_generated_tests(generate_good_blinfo_test, yes_blinfo, test_make_repo)
|
||||
add_generated_tests(generate_bad_blinfo_test, no_blinfo, test_make_repo)
|
||||
|
||||
|
Reference in New Issue
Block a user