Improve make_repo.py

This cleans up make_repo.py a bit, using file extensions to determine
file type.

This also loosens the testing repo generation, as the existing
test required matching a predifed expected output which had to be
updated on every change (essentially making it a moot test, as the
reference output was obtained from the functions output).
The new test just checks if the output has the same number of packages
as the input dir has addons.

Tips on how best to test these sorts of "higher level" functions (if at
all) would be welcome :)
This commit is contained in:
gandalf3
2017-07-04 23:56:19 -07:00
parent 12533268fc
commit 3847cc877f
4 changed files with 880 additions and 70 deletions

View File

@@ -17,29 +17,35 @@ class test_make_repo(unittest.TestCase):
def test_extract_blinfo_from_nonexistent(self):
test_file = 'file_that_doesnt_exist'
self.assertRaises(
FileNotFoundError,
make_repo.extract_blinfo,
self.addon_path / test_file
)
with self.assertRaises(FileNotFoundError):
make_repo.extract_blinfo(self.addon_path / test_file)
def test_make_repo_valid(self):
make_repo.make_repo(self.helper_path / 'addons')
repojson = Path.cwd() / 'repo.json'
reference_repojson = self.helper_path / 'repo.json'
# def test_make_repo_valid(self):
# reference_repo = make_repo.make_repo(self.helper_path / 'addons', "test repo")
# repojson = Path.cwd() / 'repo.json'
# reference_repojson = self.helper_path / 'repo.json'
#
# try:
# with repojson.open('r') as repolist_f:
# with reference_repojson.open('r') as ref_repolist_f:
# repolist = json.loads(repolist_f.read())
# ref_repolist = json.loads(ref_repolist_f.read())
# self.assertEqual(repolist, ref_repolist)
# finally:
# # repojson.unlink()
# pass
try:
with repojson.open('r') as repolist_f:
with reference_repojson.open('r') as ref_repolist_f:
repolist = json.loads(repolist_f.read())
ref_repolist = json.loads(ref_repolist_f.read())
self.assertEqual(repolist, ref_repolist)
finally:
repojson.unlink()
def test_package_quantity(self):
repo = make_repo.make_repo(self.addon_path, "name of the repo")
acceptible_addons = [
f for f in self.addon_path.iterdir()
if not f.match('*nonaddon*')
]
self.assertEqual(len(repo.packages), len(acceptible_addons))
def test_make_repo_from_nonexistent(self):
with self.assertRaises(FileNotFoundError):
make_repo.make_repo(Path('in_a_galaxy_far_far_away'))
make_repo.make_repo(Path('in_a_galaxy_far_far_away'), "somename")
# addons which should contain bl_infos
yes_blinfo = [