on xenial help sign in
Make it optional to use the mock data dirs.
243d542Leo Arias
tests/autopilot/unity8/__init__.py+15−11
@@ -88,28 +88,31 @@ def get_binary_path(binary="unity8"):
88 return binary_path
88 return binary_path
89
89
90
90
91−def get_data_dirs():
91+def get_data_dirs(data_dirs_mock_enabled=True):
92 """Prepend a mock data path to XDG_DATA_DIRS."""
92 """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():
93 if running_installed_tests():
105 if running_installed_tests():
94 data_path = "/usr/share/unity8/mocks/data"
106 data_path = "/usr/share/unity8/mocks/data"
95 else:
107 else:
96 data_path = "../../mocks/data"
108 data_path = "../../mocks/data"
97− full_data_path = os.path.abspath(
109+ return os.path.abspath(
98 os.path.join(
110 os.path.join(
99 os.path.dirname(__file__),
111 os.path.dirname(__file__),
100 data_path
112 data_path
101 )
113 )
102 )
114 )
103
115
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−
113
116
114def _get_xdg_env_path():
117def _get_xdg_env_path():
115 path = os.getenv("XDG_DATA_DIRS")
118 path = os.getenv("XDG_DATA_DIRS")
@@ -129,6 +132,7 @@ def _get_xdg_upstart_env():
129 except subprocess.CalledProcessError:
132 except subprocess.CalledProcessError:
130 return None
133 return None
131
134
135+
132def get_grid_size():
136def get_grid_size():
133 grid_size = os.getenv('GRID_UNIT_PX')
137 grid_size = os.getenv('GRID_UNIT_PX')
134 if grid_size is None:
138 if grid_size is None:
tests/autopilot/unity8/application_lifecycle/tests/test_url_dispatcher.py+2
@@ -37,6 +37,8 @@ class URLDispatcherTestCase(tests.UnityTestCase):
37 if platform.model() == 'Desktop':
37 if platform.model() == 'Desktop':
38 self.skipTest("URL dispatcher doesn't work on the desktop.")
38 self.skipTest("URL dispatcher doesn't work on the desktop.")
39 super(URLDispatcherTestCase, self).setUp()
39 super(URLDispatcherTestCase, self).setUp()
40+ self._qml_mock_enabled = False
41+ self._data_dirs_mock_enabled = False
40 unity_proxy = self.launch_unity()
42 unity_proxy = self.launch_unity()
41 process_helpers.unlock_unity(unity_proxy)
43 process_helpers.unlock_unity(unity_proxy)
42
44
tests/autopilot/unity8/process_helpers.py+2−1
@@ -111,7 +111,8 @@ def restart_unity(*args):
111 status = _get_unity_status()
111 status = _get_unity_status()
112 if "start/" in status:
112 if "start/" in status:
113 try:
113 try:
114− output = subprocess.check_output(['/sbin/initctl', 'stop', 'unity8'])
114+ output = subprocess.check_output(
115+ ['/sbin/initctl', 'stop', 'unity8'])
115 logger.info(output)
116 logger.info(output)
116 except subprocess.CalledProcessError as e:
117 except subprocess.CalledProcessError as e:
117 e.args += (
118 e.args += (
tests/autopilot/unity8/shell/tests/__init__.py+2−1
@@ -139,6 +139,7 @@ class UnityTestCase(AutopilotTestCase):
139 self._proxy = None
139 self._proxy = None
140 self._lightdm_mock_type = None
140 self._lightdm_mock_type = None
141 self._qml_mock_enabled = True
141 self._qml_mock_enabled = True
142+ self._data_dirs_mock_enabled = True
142 self._environment = {}
143 self._environment = {}
143
144
144 self._patch_data_dirs()
145 self._patch_data_dirs()
@@ -321,7 +322,7 @@ class UnityTestCase(AutopilotTestCase):
321 logger.warning("Appears unity was already stopped!")
322 logger.warning("Appears unity was already stopped!")
322
323
323 def _patch_data_dirs(self):
324 def _patch_data_dirs(self):
324− data_dirs = get_data_dirs()
325+ data_dirs = get_data_dirs(self._data_dirs_mock_enabled)
325 if data_dirs is not None:
326 if data_dirs is not None:
326 self._environment['XDG_DATA_DIRS'] = data_dirs
327 self._environment['XDG_DATA_DIRS'] = data_dirs
327
328