on xenial help sign in
Make it optional to use the mock data dirs.
commit243d542ef185690248a6630219ccb9f821a90eb1 authorLeo Arias <leo.arias@canonical.com> dateThu 6 Feb 2014, 10:03 (13 years ago) parent6c9636a
4 files changed+21−13
tests/autopilot/unity8/__init__.py+15−11 tests/autopilot/unity8/application_lifecycle/tests/test_url_dispatcher.py+2 tests/autopilot/unity8/process_helpers.py+2−1 tests/autopilot/unity8/shell/tests/__init__.py+2−1
tests/autopilot/unity8/__init__.py+15−11
@@ -88,28 +88,31 @@ def get_binary_path(binary="unity8"):
8888 return binary_path
8989
9090
91−def get_data_dirs():
91+def get_data_dirs(data_dirs_mock_enabled=True):
9292 """Prepend a mock data path to XDG_DATA_DIRS."""
93+ data_dirs = _get_xdg_env_path()
94+ if data_dirs_mock_enabled:
95+ mock_data_path = _get_full_mock_data_path()
96+ if os.path.exists(mock_data_path):
97+ if data_dirs is not None:
98+ data_dirs = '{0}:{1}'.format(mock_data_path, data_dirs)
99+ else:
100+ data_dirs = mock_data_path
101+ return data_dirs
102+
103+
104+def _get_full_mock_data_path():
93105 if running_installed_tests():
94106 data_path = "/usr/share/unity8/mocks/data"
95107 else:
96108 data_path = "../../mocks/data"
97− full_data_path = os.path.abspath(
109+ return os.path.abspath(
98110 os.path.join(
99111 os.path.dirname(__file__),
100112 data_path
101113 )
102114 )
103115
104− if os.path.exists(full_data_path):
105− xdg_path = _get_xdg_env_path()
106− if xdg_path is not None:
107− return "{0}:{1}".format(full_data_path, xdg_path)
108− else:
109− return full_data_path
110− else:
111− return None
112−
113116
114117def _get_xdg_env_path():
115118 path = os.getenv("XDG_DATA_DIRS")
@@ -129,6 +132,7 @@ def _get_xdg_upstart_env():
129132 except subprocess.CalledProcessError:
130133 return None
131134
135+
132136def get_grid_size():
133137 grid_size = os.getenv('GRID_UNIT_PX')
134138 if grid_size is None:
tests/autopilot/unity8/application_lifecycle/tests/test_url_dispatcher.py+2
@@ -37,6 +37,8 @@ class URLDispatcherTestCase(tests.UnityTestCase):
3737 if platform.model() == 'Desktop':
3838 self.skipTest("URL dispatcher doesn't work on the desktop.")
3939 super(URLDispatcherTestCase, self).setUp()
40+ self._qml_mock_enabled = False
41+ self._data_dirs_mock_enabled = False
4042 unity_proxy = self.launch_unity()
4143 process_helpers.unlock_unity(unity_proxy)
4244
tests/autopilot/unity8/process_helpers.py+2−1
@@ -111,7 +111,8 @@ def restart_unity(*args):
111111 status = _get_unity_status()
112112 if "start/" in status:
113113 try:
114− output = subprocess.check_output(['/sbin/initctl', 'stop', 'unity8'])
114+ output = subprocess.check_output(
115+ ['/sbin/initctl', 'stop', 'unity8'])
115116 logger.info(output)
116117 except subprocess.CalledProcessError as e:
117118 e.args += (
tests/autopilot/unity8/shell/tests/__init__.py+2−1
@@ -139,6 +139,7 @@ class UnityTestCase(AutopilotTestCase):
139139 self._proxy = None
140140 self._lightdm_mock_type = None
141141 self._qml_mock_enabled = True
142+ self._data_dirs_mock_enabled = True
142143 self._environment = {}
143144
144145 self._patch_data_dirs()
@@ -321,7 +322,7 @@ class UnityTestCase(AutopilotTestCase):
321322 logger.warning("Appears unity was already stopped!")
322323
323324 def _patch_data_dirs(self):
324− data_dirs = get_data_dirs()
325+ data_dirs = get_data_dirs(self._data_dirs_mock_enabled)
325326 if data_dirs is not None:
326327 self._environment['XDG_DATA_DIRS'] = data_dirs
327328