chiark / gitweb /
Merge branch 'auto-detect-java-homes' into 'master'
[fdroidserver.git] / tests / metadata.TestCase
1 #!/usr/bin/env python2
2 # -*- coding: utf-8 -*-
3
4 # http://www.drdobbs.com/testing/unit-testing-with-python/240165163
5
6 import inspect
7 import optparse
8 import os
9 import pickle
10 import sys
11 import unittest
12
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)
18
19 import fdroidserver.common
20 import fdroidserver.metadata
21
22
23 class MetadataTest(unittest.TestCase):
24     '''fdroidserver/metadata.py'''
25
26     def test_read_metadata(self):
27         testsdir = os.path.dirname(__file__)
28         os.chdir(testsdir)
29
30         self.maxDiff = None
31
32         # these need to be set to prevent code running on None, only
33         # 'accepted_formats' is actually used in metadata.py
34         config = dict()
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
39
40         apps = fdroidserver.metadata.read_metadata(xref=True)
41         for appid in ('org.smssecure.smssecure', 'org.adaway', 'net.osmand.plus', 'org.videolan.vlc'):
42             app = apps[appid]
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)
52
53
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'])
59
60     newSuite = unittest.TestSuite()
61     newSuite.addTest(unittest.makeSuite(MetadataTest))
62     unittest.main()