This repository has been archived on 2023-02-07. You can view files and clone it, but cannot push or open issues or pull requests.
Files
blender-package-manager-addon/tests/test_blenderpack.py

65 lines
1.9 KiB
Python
Raw Normal View History

#!/usr/bin/env python3
import unittest
2017-06-23 20:05:10 -07:00
from pathlib import Path
import os
import json
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 18:00:29 -07:00
def test_extract_blinfo_from_nonexistent(self):
test_file = 'file_that_doesnt_exist'
2017-06-22 18:00:29 -07:00
self.assertRaises(
FileNotFoundError,
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
)
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-22 18:00:29 -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 20:05:10 -07:00
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):
2017-06-23 20:05:10 -07:00
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):
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:
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)