Clean up tests

No need to test on complete addons.
This commit adds a few test cases and some automated test
generation.
This commit is contained in:
2017-06-23 18:53:07 -07:00
parent 1ff2b055a6
commit d06af2fed0
23 changed files with 123 additions and 7251 deletions

View File

@@ -7,38 +7,56 @@ import blenderpack
class test_blenderpack_make_repo(unittest.TestCase):
helper_path = os.path.join('tests', 'test_helpers')
def test_extract_blinfo_from_file(self):
with open(os.path.join(self.helper_path, 'ivy_gen_blinfo.txt'), 'r') as f:
expectation = f.read()
reality = str(blenderpack.extract_blinfo(os.path.join(self.helper_path, 'addons', 'add_curve_ivygen.py')))
self.assertEqual(expectation, reality)
def test_extract_blinfo_from_zip(self):
with open(os.path.join(self.helper_path, 'extra_objects_blinfo.txt'), 'r') as f:
expectation = f.read()
reality = str(blenderpack.extract_blinfo(os.path.join(self.helper_path, 'addons', 'add_curve_extra_objects.zip')))
self.assertEqual(expectation, reality)
def test_extract_blinfo_from_dir(self):
with open(os.path.join(self.helper_path, 'extra_objects_blinfo.txt'), 'r') as f:
expectation = f.read()
reality = str(blenderpack.extract_blinfo(os.path.join(self.helper_path, 'addons', 'add_curve_extra_objects/')))
self.assertEqual(expectation, reality)
addon_path = os.path.join(helper_path, 'addons')
def test_extract_blinfo_from_nonexistent(self):
test_file = 'file_that_doesnt_exist'
self.assertRaises(
FileNotFoundError,
lambda: blenderpack.extract_blinfo(os.path.join(self.helper_path, 'addons', 'notathing'))
blenderpack.extract_blinfo,
os.path.join(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,
os.path.join(self.addon_path, test_file)
)
def test_make_repo_valid(self):
blenderpack.make_repo(os.path.join(self.helper_path, 'addons'))
repojson = os.path.join(self.helper_path, 'addons', 'repo.json')
self.assertTrue(os.path.exists(repojson))
with open(repojson, 'r') as f:
json.loads(f.read())
os.remove(repojson)
self.fail('unfinished test')
def test_make_repo_from_nonexistent(self):
blenderpack.make_repo(os.path.join(self.helper_path, 'addons'))
self.fail('unfinished test')
# 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 test(self):
reality = str(blenderpack.extract_blinfo(os.path.join(self.addon_path, test_file)))
with open(os.path.join(self.helper_path, test_file + '_output'), 'r') as f:
expectation = 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)