3 # http://www.drdobbs.com/testing/unit-testing-with-python/240165163
12 localmodule = os.path.realpath(
13 os.path.join(os.path.dirname(inspect.getfile(inspect.currentframe())), '..'))
14 print('localmodule: ' + localmodule)
15 if localmodule not in sys.path:
16 sys.path.insert(0, localmodule)
18 import fdroidserver.common
19 import fdroidserver.metadata
22 class MetadataTest(unittest.TestCase):
23 '''fdroidserver/metadata.py'''
25 def test_read_metadata(self):
26 testsdir = os.path.dirname(__file__)
31 # these need to be set to prevent code running on None, only
32 # 'accepted_formats' is actually used in metadata.py
34 config['sdk_path'] = '/opt/android-sdk'
35 config['ndk_paths'] = dict()
36 config['accepted_formats'] = ['json', 'txt', 'xml', 'yml']
37 fdroidserver.common.config = config
39 apps = fdroidserver.metadata.read_metadata(xref=True)
40 for appid in ('org.smssecure.smssecure', 'org.adaway', 'net.osmand.plus', 'org.videolan.vlc'):
42 savepath = os.path.join('metadata', appid + '.pickle')
43 frommeta = app.field_dict()
44 self.assertTrue(appid in apps)
45 with open(savepath, 'rb') as f:
46 frompickle = pickle.load(f)
47 self.assertEqual(frommeta, frompickle)
48 # Uncomment to overwrite
49 # with open(savepath, 'wb') as f:
50 # pickle.dump(frommeta, f)
53 if __name__ == "__main__":
54 parser = optparse.OptionParser()
55 parser.add_option("-v", "--verbose", action="store_true", default=False,
56 help="Spew out even more information than normal")
57 (fdroidserver.common.options, args) = parser.parse_args(['--verbose'])
59 newSuite = unittest.TestSuite()
60 newSuite.addTest(unittest.makeSuite(MetadataTest))