backing up
[vsorcdistro/.git] / ryu / build / lib.linux-armv7l-2.7 / ryu / tests / unit / test_requirements.py
1 # Copyright (C) 2016 Nippon Telegraph and Telephone Corporation.
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 #    http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
12 # implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15
16 import logging
17 import os
18 import sys
19 import unittest
20
21 import pkg_resources
22 from six.moves import urllib
23
24 from nose.tools import ok_
25
26
27 LOG = logging.getLogger(__name__)
28
29 MOD_DIR = os.path.dirname('file://' + sys.modules[__name__].__file__)
30 _RYU_REQUIREMENTS_FILES = [
31     '../../../tools/pip-requires',
32     '../../../tools/optional-requires',
33 ]
34 RYU_REQUIREMENTS_FILES = [
35     os.path.join(MOD_DIR, f) for f in _RYU_REQUIREMENTS_FILES]
36
37 OPENSTACK_REQUIREMENTS_REPO = 'https://github.com/openstack/requirements'
38 OPENSTACK_REQUIREMENTS_URL = (
39     'https://github.com/openstack/requirements/raw/master/')
40 _OPENSTACK_REQUIREMENTS_FILES = [
41     'requirements.txt',
42     'global-requirements.txt',
43 ]
44 OPENSTACK_REQUIREMENTS_FILES = [
45     urllib.parse.urljoin(OPENSTACK_REQUIREMENTS_URL, f)
46     for f in _OPENSTACK_REQUIREMENTS_FILES]
47
48
49 def _get_requirements(files):
50     requirements = {}
51     for f in files:
52         response = urllib.request.urlopen(f)
53         contents = response.read().decode('utf-8')
54         for r in pkg_resources.parse_requirements(contents):
55             requirements[r.name] = str(r)
56
57     return requirements
58
59
60 OPENSTACK_REQUIREMENTS = _get_requirements(OPENSTACK_REQUIREMENTS_FILES)
61 RYU_REQUIREMENTS = _get_requirements(RYU_REQUIREMENTS_FILES)
62
63
64 class TestRequirements(unittest.TestCase):
65     """
66     Test whether the requirements of Ryu has no conflict with that
67     of other projects.
68     """
69
70     def setUp(self):
71         pass
72
73     def tearDown(self):
74         pass
75
76     def test_with_openstack_requirements(self):
77         try:
78             for name, req in OPENSTACK_REQUIREMENTS.items():
79                 if name in RYU_REQUIREMENTS:
80                     ok_(pkg_resources.require(req))
81         except pkg_resources.VersionConflict as e:
82             LOG.exception(
83                 'Some requirements of Ryu are conflicting with that of '
84                 'OpenStack project: %s', OPENSTACK_REQUIREMENTS_REPO)
85             raise e