|
| 1 | +#!/usr/bin/env python |
| 2 | + |
| 3 | +"""Test FAUCET packaging""" |
| 4 | + |
| 5 | +# Copyright (C) 2015 Brad Cowie, Christopher Lorier and Joe Stringer. |
| 6 | +# Copyright (C) 2015 Research and Innovation Advanced Network New Zealand Ltd. |
| 7 | +# Copyright (C) 2015--2018 The Contributors |
| 8 | +# |
| 9 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 10 | +# you may not use this file except in compliance with the License. |
| 11 | +# You may obtain a copy of the License at |
| 12 | +# |
| 13 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 14 | +# |
| 15 | +# Unless required by applicable law or agreed to in writing, software |
| 16 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 17 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 18 | +# See the License for the specific language governing permissions and |
| 19 | +# limitations under the License. |
| 20 | + |
| 21 | +import os |
| 22 | +import unittest |
| 23 | +import pip.req |
| 24 | + |
| 25 | +from deb_pkg_tools.control import deb822_from_string, parse_control_fields |
| 26 | + |
| 27 | +class CheckRequirementsTestCase(unittest.TestCase): # pytype: disable=module-attr |
| 28 | + """Test packaging requirements.""" |
| 29 | + |
| 30 | + def test_requirements_match(self): |
| 31 | + """Test all requirements are listed as apt package dependencies.""" |
| 32 | + |
| 33 | + SRC_DIR = os.path.join(os.path.dirname(os.path.realpath(__file__)), '../../../') |
| 34 | + control_file = os.path.join(SRC_DIR, 'debian/control') |
| 35 | + requirements_file = os.path.join(SRC_DIR, 'requirements.txt') |
| 36 | + |
| 37 | + real_name = { |
| 38 | + 'msgpack-python': 'python3-msgpack', |
| 39 | + 'pyyaml': 'python3-yaml' |
| 40 | + } |
| 41 | + |
| 42 | + with open(control_file) as handle: |
| 43 | + control = handle.read() |
| 44 | + |
| 45 | + faucet_dpkg = str() |
| 46 | + for line in control.split("\n"): |
| 47 | + if line.startswith("Package: python3-faucet"): |
| 48 | + faucet_dpkg += line |
| 49 | + elif len(faucet_dpkg) > 0: |
| 50 | + if not line: |
| 51 | + break |
| 52 | + faucet_dpkg += "{}\n".format(line) |
| 53 | + |
| 54 | + faucet_dpkg = parse_control_fields(deb822_from_string(faucet_dpkg)) |
| 55 | + faucet_dpkg_deps = [x.name for x in faucet_dpkg['Depends']] |
| 56 | + |
| 57 | + for item in pip.req.parse_requirements(requirements_file, |
| 58 | + session="unittest"): |
| 59 | + if isinstance(item, pip.req.InstallRequirement): |
| 60 | + if item.name in real_name: |
| 61 | + self.assertIn(real_name[item.name], faucet_dpkg_deps) |
| 62 | + else: |
| 63 | + self.assertIn("python3-{}".format(item.name), faucet_dpkg_deps) |
| 64 | + |
| 65 | + |
| 66 | +if __name__ == "__main__": |
| 67 | + unittest.main() # pytype: disable=module-attr |
0 commit comments