on xenial help sign in
Checks both then env and upstart env for the currently set XDG_DATA_DIRS so they can be set correctly for the test.

Approved by Michał Sawicz.

commit39d6b5e40e5028ed5bb7b9497b62552769c63ea3 authorChristopher Lee <chris.lee@canonical.com> dateThu 17 Oct 2013, 11:10 (13 years ago) parent2ccff6aa6277a9
2 files changed+47−12
tests/autopilot/unity8/__init__.py+39−9 tests/autopilot/unity8/shell/tests/__init__.py+8−3
tests/autopilot/unity8/__init__.py+39−9
@@ -55,7 +55,7 @@ def get_mocks_library_path():
5555 mock_path = os.path.join(
5656 "../lib/",
5757 sysconfig.get_config_var('MULTIARCH'),
58− "/unity8/qml/mocks/"
58+ "unity8/qml/mocks/"
5959 )
6060 lib_path = get_lib_path()
6161 ld_library_path = os.path.abspath(
@@ -87,17 +87,47 @@ def get_binary_path(binary="unity8"):
8787 raise RuntimeError("Unable to locate %s binary: %r" % (binary, e))
8888 return binary_path
8989
90+
9091def get_data_dirs():
9192 """Prepend a mock data path to XDG_DATA_DIRS."""
92− data_path = os.path.abspath(
93− os.path.join(os.path.dirname(__file__),
94− running_installed_tests() and "/usr/share/unity8/mocks/data" or "../../mocks/data"
95− ))
96− xdg_path = os.getenv("XDG_DATA_DIRS")
97− if xdg_path:
98− return "{0}:{1}".format(data_path, xdg_path)
93+ if running_installed_tests():
94+ data_path = "/usr/share/unity8/mocks/data"
95+ else:
96+ data_path = "../../mocks/data"
97+ full_data_path = os.path.abspath(
98+ os.path.join(
99+ os.path.dirname(__file__),
100+ data_path
101+ )
102+ )
103+
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
99110 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
101131
102132def get_grid_size():
103133 grid_size = os.getenv('GRID_UNIT_PX')
tests/autopilot/unity8/shell/tests/__init__.py+8−3
@@ -121,9 +121,9 @@ class UnityTestCase(AutopilotTestCase):
121121 self._proxy = None
122122 self._lightdm_mock_type = None
123123 self._qml_mock_enabled = True
124− self._environment = {
125− 'XDG_DATA_DIRS': get_data_dirs()
126− }
124+ self._environment = {}
125+
126+ self._patch_data_dirs()
127127
128128 #### FIXME: This is a work around re: lp:1238417 ####
129129 if model() != "Desktop":
@@ -300,6 +300,11 @@ class UnityTestCase(AutopilotTestCase):
300300 except subprocess.CalledProcessError:
301301 logger.warning("Appears unity was already stopped!")
302302
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+
303308 def patch_lightdm_mock(self, mock_type='single'):
304309 self._lightdm_mock_type = mock_type
305310 logger.info("Setting up LightDM mock type '%s'", mock_type)