summaryrefslogtreecommitdiffstats
path: root/meta/lib/patchtest/tests/test_metadata_license.py
diff options
context:
space:
mode:
Diffstat (limited to 'meta/lib/patchtest/tests/test_metadata_license.py')
-rw-r--r--meta/lib/patchtest/tests/test_metadata_license.py55
1 files changed, 55 insertions, 0 deletions
diff --git a/meta/lib/patchtest/tests/test_metadata_license.py b/meta/lib/patchtest/tests/test_metadata_license.py
new file mode 100644
index 0000000000..16604dbfb1
--- /dev/null
+++ b/meta/lib/patchtest/tests/test_metadata_license.py
@@ -0,0 +1,55 @@
1# Checks related to the patch's LIC_FILES_CHKSUM metadata variable
2#
3# Copyright (C) 2016 Intel Corporation
4#
5# SPDX-License-Identifier: GPL-2.0
6
7import base
8import os
9from data import PatchTestInput
10
11class License(base.Metadata):
12 metadata = 'LICENSE'
13 invalid_license = 'PATCHTESTINVALID'
14
15 def setUp(self):
16 # these tests just make sense on patches that can be merged
17 if not PatchTestInput.repo.canbemerged:
18 self.skip('Patch cannot be merged')
19
20 def test_license_presence(self):
21 if not self.added:
22 self.skip('No added recipes, skipping test')
23
24 # TODO: this is a workaround so we can parse the recipe not
25 # containing the LICENSE var: add some default license instead
26 # of INVALID into auto.conf, then remove this line at the end
27 auto_conf = os.path.join(os.environ.get('BUILDDIR'), 'conf', 'auto.conf')
28 open_flag = 'w'
29 if os.path.exists(auto_conf):
30 open_flag = 'a'
31 with open(auto_conf, open_flag) as fd:
32 for pn in self.added:
33 fd.write('LICENSE ??= "%s"\n' % self.invalid_license)
34
35 no_license = False
36 for pn in self.added:
37 rd = self.tinfoil.parse_recipe(pn)
38 license = rd.getVar(self.metadata)
39 if license == self.invalid_license:
40 no_license = True
41 break
42
43 # remove auto.conf line or the file itself
44 if open_flag == 'w':
45 os.remove(auto_conf)
46 else:
47 fd = open(auto_conf, 'r')
48 lines = fd.readlines()
49 fd.close()
50 with open(auto_conf, 'w') as fd:
51 fd.write(''.join(lines[:-1]))
52
53 if no_license:
54 self.fail('Recipe does not have the LICENSE field set', 'Include a LICENSE into the new recipe')
55