on xenial help sign in
Grab xdg_data_dir from upstart env if needed.
cac7bccChristopher Lee
tests/autopilot/unity8/__init__.py+38−8
@@ -87,17 +87,47 @@ def get_binary_path(binary="unity8"):
87 raise RuntimeError("Unable to locate %s binary: %r" % (binary, e))
87 raise RuntimeError("Unable to locate %s binary: %r" % (binary, e))
88 return binary_path
88 return binary_path
89
89
90+
90def get_data_dirs():
91def get_data_dirs():
91 """Prepend a mock data path to XDG_DATA_DIRS."""
92 """Prepend a mock data path to XDG_DATA_DIRS."""
93+ if running_installed_tests():
94+ data_path = "/usr/share/unity8/mocks/data"
95+ else:
96+ data_path = "../../mocks/data"
92− data_path = os.path.abspath(
97+ full_data_path = os.path.abspath(
98+ os.path.join(
93− os.path.join(os.path.dirname(__file__),
99+ os.path.dirname(__file__),
94− running_installed_tests() and "/usr/share/unity8/mocks/data" or "../../mocks/data"
100+ data_path
95− ))
101+ )
96− xdg_path = os.getenv("XDG_DATA_DIRS")
102+ )
103+
104+ if os.path.exists(full_data_path):
105+ xdg_path = _get_xdg_env_path()
97− if xdg_path:
106+ if xdg_path is not None:
98− return "{0}:{1}".format(data_path, xdg_path)
107+ return "{0}:{1}".format(data_path, xdg_path)
108+ else:
109+ return full_data_path
99 else:
110 else:
100− return data_path
111+ return None
112+
113+
114+def _get_xdg_env_path():
115+ path = os.getenv("XDG_DATA_DIRS")
116+ if path is None:
117+ path = _get_xdg_upstart_env()
118+ return path
119+
120+
121+def _get_xdg_upstart_env():
122+ try:
123+ return subprocess.check_output([
124+ "/sbin/initctl",
125+ "get-env",
126+ "--global",
127+ "XDG_DATA_DIRS"
128+ ]).rstrip()
129+ except subprocess.CalledProcessError:
130+ return None
101
131
102def get_grid_size():
132def get_grid_size():
103 grid_size = os.getenv('GRID_UNIT_PX')
133 grid_size = os.getenv('GRID_UNIT_PX')
tests/autopilot/unity8/shell/tests/__init__.py+8−3
@@ -121,9 +121,9 @@ class UnityTestCase(AutopilotTestCase):
121 self._proxy = None
121 self._proxy = None
122 self._lightdm_mock_type = None
122 self._lightdm_mock_type = None
123 self._qml_mock_enabled = True
123 self._qml_mock_enabled = True
124− self._environment = {
124+ self._environment = {}
125− 'XDG_DATA_DIRS': get_data_dirs()
125+
126− }
126+ self._patch_data_dirs()
127
127
128 #### FIXME: This is a work around re: lp:1238417 ####
128 #### FIXME: This is a work around re: lp:1238417 ####
129 if model() != "Desktop":
129 if model() != "Desktop":
@@ -300,6 +300,11 @@ class UnityTestCase(AutopilotTestCase):
300 except subprocess.CalledProcessError:
300 except subprocess.CalledProcessError:
301 logger.warning("Appears unity was already stopped!")
301 logger.warning("Appears unity was already stopped!")
302
302
303+ def _patch_data_dirs(self):
304+ data_dirs = get_data_dirs()
305+ if data_dirs is not None:
306+ self._environment['XDG_DATA_DIRS'] = data_dirs
307+
303 def patch_lightdm_mock(self, mock_type='single'):
308 def patch_lightdm_mock(self, mock_type='single'):
304 self._lightdm_mock_type = mock_type
309 self._lightdm_mock_type = mock_type
305 logger.info("Setting up LightDM mock type '%s'", mock_type)
310 logger.info("Setting up LightDM mock type '%s'", mock_type)