66 lines
1.8 KiB
Python
66 lines
1.8 KiB
Python
#!/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 = helper_path / 'addons'
|
|
|
|
def test_extract_blinfo_from_nonexistent(self):
|
|
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,
|
|
self.addon_path / test_file
|
|
)
|
|
|
|
def test_make_repo_valid(self):
|
|
blenderpack.make_repo(self.helper_path / 'addons')
|
|
repojson = Path.cwd() / 'repo.json'
|
|
|
|
try:
|
|
with repojson.open('r') as f:
|
|
json.loads(f.read())
|
|
finally:
|
|
repojson.unlink()
|
|
|
|
self.fail('unfinished test')
|
|
|
|
def test_make_repo_from_nonexistent(self):
|
|
blenderpack.make_repo(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(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)
|
|
|