forked from metabrainz/picard-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
79 lines (57 loc) · 2.29 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import os
import glob
import unittest
from generate import *
# The file that contains json data
plugin_file = "plugins.json"
# The directory which contains plugin files
plugin_dir = "plugins"
class GenerateTestCase(unittest.TestCase):
"""Run tests"""
def test_generate_json(self):
"""
Generates the json data from all the plugins
and asserts that all plugins are accounted for.
"""
print("\n#########################################\n")
build_json()
# Load the json file
with open(plugin_file, "r") as in_file:
plugin_json = json.load(in_file)["plugins"]
# All top level directories in plugin_dir
plugin_folders = next(os.walk(plugin_dir))[1]
# Number of entries in the json should be equal to the
# number of folders in plugin_dir
self.assertEqual(len(plugin_json), len(plugin_folders))
def test_generate_zip(self):
"""
Generates zip files for all folders and asserts
that all folders are accounted for.
"""
print("\n\n#########################################\n")
zip_files()
# All zip files in plugin_dir
plugin_zips = glob.glob(os.path.join(plugin_dir,"*.zip"))
# All top level directories in plugin_dir
plugin_folders = next(os.walk(plugin_dir))[1]
# Number of folders should be equal to number of zips
self.assertEqual(len(plugin_zips), len(plugin_folders))
def test_valid_json(self):
"""
Asserts that the json data contains all the fields
for all the plugins.
"""
print("\n#########################################\n")
build_json()
# Load the json file
with open(plugin_file, "r") as in_file:
plugin_json = json.load(in_file)["plugins"]
# All plugins should contain all required fields
for module_name, data in plugin_json.items():
self.assertIsInstance(data['name'], basestring)
self.assertIsInstance(data['api_version'], basestring)
self.assertIsInstance(data['author'], basestring)
self.assertIsInstance(data['downloads'], int)
self.assertIsInstance(data['description'], basestring)
if __name__ == '__main__':
unittest.main()