#!/usr/bin/env python3 import unittest from pathlib import Path import os import json import blenderpack class test_blenderpack_make_repo(unittest.TestCase): helper_path = Path('tests', 'test_helpers') addon_path = Path(helper_path, 'addons') def test_extract_blinfo_from_nonexistent(self): test_file = 'file_that_doesnt_exist' self.assertRaises( FileNotFoundError, blenderpack.extract_blinfo, Path(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, Path(self.addon_path, test_file) ) def test_make_repo_valid(self): blenderpack.make_repo(Path(self.helper_path, 'addons')) repojson = Path(self.helper_path, 'addons', 'repo.json') self.assertTrue(repojson.is_file()) with repojson.open('r') as f: json.loads(f.read()) os.remove(repojson) self.fail('unfinished test') def test_make_repo_from_nonexistent(self): blenderpack.make_repo(Path(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(Path(self.addon_path, test_file))) with (self.helper_path / (test_file + '_output')).open() 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)