summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2017-06-19 13:56:28 +0000
committerGerrit Code Review <review@openstack.org>2017-06-19 13:56:28 +0000
commitc9a9b5d41a7418e6a8b6df9061946245327d3bc3 (patch)
tree7e6d64c72b4f6de2f49fc03a16f22455e4f14018
parent7cb56a1628883a76d5971a850365dc9ead66b7a0 (diff)
parent572deac00be43b87546d9dd6d3d9886b0963ae1e (diff)
Merge "Fixes import_modules_recursively for Windows"
-rw-r--r--neutron/common/utils.py6
-rw-r--r--neutron/tests/unit/common/test_utils.py11
2 files changed, 13 insertions, 4 deletions
diff --git a/neutron/common/utils.py b/neutron/common/utils.py
index c8e3d86..0842684 100644
--- a/neutron/common/utils.py
+++ b/neutron/common/utils.py
@@ -23,6 +23,7 @@ import importlib
23import os 23import os
24import os.path 24import os.path
25import random 25import random
26import re
26import signal 27import signal
27import sys 28import sys
28import threading 29import threading
@@ -57,6 +58,8 @@ SYNCHRONIZED_PREFIX = 'neutron-'
57 58
58DEFAULT_THROTTLER_VALUE = 2 59DEFAULT_THROTTLER_VALUE = 2
59 60
61_SEPARATOR_REGEX = re.compile(r'[/\\]+')
62
60synchronized = lockutils.synchronized_with_prefix(SYNCHRONIZED_PREFIX) 63synchronized = lockutils.synchronized_with_prefix(SYNCHRONIZED_PREFIX)
61 64
62 65
@@ -750,6 +753,7 @@ def extract_exc_details(e):
750 753
751def import_modules_recursively(topdir): 754def import_modules_recursively(topdir):
752 '''Import and return all modules below the topdir directory.''' 755 '''Import and return all modules below the topdir directory.'''
756 topdir = _SEPARATOR_REGEX.sub('/', topdir)
753 modules = [] 757 modules = []
754 for root, dirs, files in os.walk(topdir): 758 for root, dirs, files in os.walk(topdir):
755 for file_ in files: 759 for file_ in files:
@@ -760,7 +764,7 @@ def import_modules_recursively(topdir):
760 if module == '__init__': 764 if module == '__init__':
761 continue 765 continue
762 766
763 import_base = root.replace('/', '.') 767 import_base = _SEPARATOR_REGEX.sub('.', root)
764 768
765 # NOTE(ihrachys): in Python3, or when we are not located in the 769 # NOTE(ihrachys): in Python3, or when we are not located in the
766 # directory containing neutron code, __file__ is absolute, so we 770 # directory containing neutron code, __file__ is absolute, so we
diff --git a/neutron/tests/unit/common/test_utils.py b/neutron/tests/unit/common/test_utils.py
index 0e3c49a..b609d96 100644
--- a/neutron/tests/unit/common/test_utils.py
+++ b/neutron/tests/unit/common/test_utils.py
@@ -14,8 +14,10 @@
14 14
15import os.path 15import os.path
16import random 16import random
17import re
17import sys 18import sys
18 19
20import ddt
19import eventlet 21import eventlet
20import mock 22import mock
21import netaddr 23import netaddr
@@ -689,17 +691,20 @@ class TestExcDetails(base.BaseTestCase):
689 utils.extract_exc_details(Exception()), six.text_type) 691 utils.extract_exc_details(Exception()), six.text_type)
690 692
691 693
694@ddt.ddt
692class ImportModulesRecursivelyTestCase(base.BaseTestCase): 695class ImportModulesRecursivelyTestCase(base.BaseTestCase):
693 696
694 def test_recursion(self): 697 @ddt.data('/', r'\\')
698 def test_recursion(self, separator):
695 expected_modules = ( 699 expected_modules = (
696 'neutron.tests.unit.tests.example.dir.example_module', 700 'neutron.tests.unit.tests.example.dir.example_module',
697 'neutron.tests.unit.tests.example.dir.subdir.example_module', 701 'neutron.tests.unit.tests.example.dir.subdir.example_module',
698 ) 702 )
699 for module in expected_modules: 703 for module in expected_modules:
700 sys.modules.pop(module, None) 704 sys.modules.pop(module, None)
701 modules = utils.import_modules_recursively( 705
702 os.path.dirname(tests.__file__)) 706 topdir = re.sub(r'[/\\]+', separator, os.path.dirname(tests.__file__))
707 modules = utils.import_modules_recursively(topdir)
703 for module in expected_modules: 708 for module in expected_modules:
704 self.assertIn(module, modules) 709 self.assertIn(module, modules)
705 self.assertIn(module, sys.modules) 710 self.assertIn(module, sys.modules)