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