2017-06-22 17:41:41 -07:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
import unittest
|
2017-06-23 20:05:10 -07:00
|
|
|
from pathlib import Path
|
|
|
|
import os
|
2017-06-23 19:10:26 -07:00
|
|
|
import json
|
2017-06-22 17:41:41 -07:00
|
|
|
import blenderpack
|
|
|
|
|
|
|
|
class test_blenderpack_make_repo(unittest.TestCase):
|
|
|
|
|
2017-06-23 20:05:10 -07:00
|
|
|
helper_path = Path('tests', 'test_helpers')
|
|
|
|
addon_path = Path(helper_path, 'addons')
|
2017-06-22 17:47:38 -07:00
|
|
|
|
2017-06-22 18:00:29 -07:00
|
|
|
def test_extract_blinfo_from_nonexistent(self):
|
2017-06-23 18:53:07 -07:00
|
|
|
test_file = 'file_that_doesnt_exist'
|
2017-06-22 18:00:29 -07:00
|
|
|
self.assertRaises(
|
|
|
|
FileNotFoundError,
|
2017-06-23 18:53:07 -07:00
|
|
|
blenderpack.extract_blinfo,
|
2017-06-23 20:05:10 -07:00
|
|
|
Path(self.addon_path, test_file)
|
2017-06-22 18:00:29 -07:00
|
|
|
)
|
|
|
|
|
2017-06-23 18:53:07 -07:00
|
|
|
def test_extract_blinfo_from_nonaddon(self):
|
|
|
|
test_file = 'not_an_addon.py'
|
|
|
|
self.assertRaises(
|
|
|
|
blenderpack.BadAddon,
|
|
|
|
blenderpack.extract_blinfo,
|
2017-06-23 20:05:10 -07:00
|
|
|
Path(self.addon_path, test_file)
|
2017-06-23 18:53:07 -07:00
|
|
|
)
|
2017-06-22 18:00:29 -07:00
|
|
|
|
2017-06-22 20:04:15 -07:00
|
|
|
def test_make_repo_valid(self):
|
2017-06-23 20:05:10 -07:00
|
|
|
blenderpack.make_repo(Path(self.helper_path, 'addons'))
|
|
|
|
repojson = Path(self.helper_path, 'addons', 'repo.json')
|
2017-06-23 18:53:07 -07:00
|
|
|
|
2017-06-23 20:05:10 -07:00
|
|
|
self.assertTrue(repojson.is_file())
|
|
|
|
with repojson.open('r') as f:
|
2017-06-23 18:53:07 -07:00
|
|
|
json.loads(f.read())
|
2017-06-22 17:41:41 -07:00
|
|
|
|
2017-06-23 18:53:07 -07:00
|
|
|
os.remove(repojson)
|
|
|
|
self.fail('unfinished test')
|
2017-06-22 17:41:41 -07:00
|
|
|
|
2017-06-22 20:04:15 -07:00
|
|
|
def test_make_repo_from_nonexistent(self):
|
2017-06-23 20:05:10 -07:00
|
|
|
blenderpack.make_repo(Path(self.helper_path, 'addons'))
|
2017-06-23 18:53:07 -07:00
|
|
|
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):
|
2017-06-23 20:05:10 -07:00
|
|
|
reality = str(blenderpack.extract_blinfo(Path(self.addon_path, test_file)))
|
|
|
|
with (self.helper_path / (test_file + '_output')).open() as f:
|
2017-06-23 18:53:07 -07:00
|
|
|
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)
|
|
|
|
|