forked from metabrainz/picard-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
97 lines (70 loc) · 2.73 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import os
import glob
import json
import shutil
import tempfile
import unittest
from generate import build_json, zip_files
# python 2 & 3 compatibility
try:
basestring
except NameError:
basestring = str
class GenerateTestCase(unittest.TestCase):
"""Run tests"""
# The file that contains json data
PLUGIN_FILE = "plugins.json"
# The directory which contains plugin files
PLUGIN_DIR = "plugins"
def setUp(self):
# Destination directory
self.dest_dir = tempfile.mkdtemp()
self.addCleanup(shutil.rmtree, self.dest_dir)
self.plugin_file = os.path.join(self.dest_dir, self.PLUGIN_FILE)
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(self.dest_dir)
# Load the json file
with open(self.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(self.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(self.dest_dir)
# All zip files in plugin_dir
plugin_zips = glob.glob(os.path.join(self.dest_dir, "*.zip"))
# All top level directories in plugin_dir
plugin_folders = next(os.walk(self.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(self.dest_dir)
# Load the json file
with open(self.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_versions'], list)
self.assertIsInstance(data['author'], basestring)
self.assertIsInstance(data['description'], basestring)
self.assertIsInstance(data['version'], basestring)
if __name__ == '__main__':
unittest.main()