ubuntu-sdk-team team mailing list archive
-
ubuntu-sdk-team team
-
Mailing list archive
-
Message #00338
[Merge] lp:~sergio-j-cazzolato/ubuntu-ui-toolkit/remove-upstart-tests-dependency into lp:ubuntu-ui-toolkit
Sergio Cazzolato has proposed merging lp:~sergio-j-cazzolato/ubuntu-ui-toolkit/remove-upstart-tests-dependency into lp:ubuntu-ui-toolkit.
Commit message:
This change is done to remove the dependencies with upstart in the tests.
To start apps with env vars is gonna be used the launch_test_application method provided by autopilot in its test base class which is a wrapper for the ubuntu-app-launch tools (API).
This change removes all the dependencies with upstart, so all the projects which are using the initctl api and fixtures will be impacted.
Requested reviews:
Ubuntu SDK team (ubuntu-sdk-team)
For more details, see:
https://code.launchpad.net/~sergio-j-cazzolato/ubuntu-ui-toolkit/remove-upstart-tests-dependency/+merge/315030
--
Your team Ubuntu SDK team is requested to review the proposed merge of lp:~sergio-j-cazzolato/ubuntu-ui-toolkit/remove-upstart-tests-dependency into lp:ubuntu-ui-toolkit.
=== modified file 'tests/autopilot/ubuntuuitoolkit/__init__.py'
--- tests/autopilot/ubuntuuitoolkit/__init__.py 2016-04-21 03:23:24 +0000
+++ tests/autopilot/ubuntuuitoolkit/__init__.py 2017-01-18 15:58:41 +0000
@@ -18,7 +18,6 @@
from ubuntuuitoolkit import (
base,
- environment,
fixture_setup,
tests,
ubuntu_scenarios
=== removed file 'tests/autopilot/ubuntuuitoolkit/environment.py'
--- tests/autopilot/ubuntuuitoolkit/environment.py 2014-08-28 19:05:23 +0000
+++ tests/autopilot/ubuntuuitoolkit/environment.py 1970-01-01 00:00:00 +0000
@@ -1,68 +0,0 @@
-# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
-#
-# Copyright (C) 2014 Canonical Ltd.
-#
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU Lesser General Public License as published by
-# the Free Software Foundation; version 3.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public License
-# along with this program. If not, see <http://www.gnu.org/licenses/>.
-
-import logging
-import subprocess
-
-from autopilot import logging as autopilot_logging
-
-
-logger = logging.getLogger(__name__)
-
-
-def is_initctl_env_var_set(variable, global_=False):
- """Check True if an initctl environment variable is set.
-
- :param variable: The name of the variable to check.
- :param global: if True, the method will operate on the global environment
- table. Default is False.
- :return: True if the variable is set. False otherwise.
-
- """
- try:
- get_initctl_env_var(variable, global_)
- return True
- except subprocess.CalledProcessError:
- return False
-
-
-def get_initctl_env_var(variable, global_=False):
- """Return the value of an initctl environment variable."""
- command = ['/sbin/initctl', 'get-env', variable]
- if global_:
- command += ['--global']
- output = subprocess.check_output(
- command, stderr=subprocess.STDOUT, universal_newlines=True)
- return output.rstrip()
-
-
-@autopilot_logging.log_action(logger.info)
-def set_initctl_env_var(variable, value, global_=False):
- """Set the value of an initctl environment variable."""
- command = ['/sbin/initctl', 'set-env', '%s=%s' % (variable, value)]
- if global_:
- command += ['--global']
- subprocess.call(command, stderr=subprocess.STDOUT, universal_newlines=True)
-
-
-@autopilot_logging.log_action(logger.info)
-def unset_initctl_env_var(variable, global_=False):
- """Remove an initctl environment variable."""
- command = ['/sbin/initctl', 'unset-env', variable]
- if global_:
- command += ['--global']
- subprocess.call(
- command, stderr=subprocess.STDOUT, universal_newlines=True)
=== modified file 'tests/autopilot/ubuntuuitoolkit/fixture_setup.py'
--- tests/autopilot/ubuntuuitoolkit/fixture_setup.py 2015-07-09 21:55:03 +0000
+++ tests/autopilot/ubuntuuitoolkit/fixture_setup.py 2017-01-18 15:58:41 +0000
@@ -26,7 +26,7 @@
from autopilot import display
from gi.repository import Gio
-from ubuntuuitoolkit import base, environment
+from ubuntuuitoolkit import base
DEFAULT_QML_FILE_CONTENTS = ("""
@@ -156,45 +156,6 @@
url_dispatcher_file_path, shell=True)
-class InitctlEnvironmentVariable(fixtures.Fixture):
- """Set the value of initctl environment variables."""
-
- def __init__(self, global_=False, **kwargs):
- super().__init__()
- # Added one level of indirection to be able to spy the calls to
- # environment during tests.
- self.environment = environment
- self.variables = kwargs
- self.global_ = global_
-
- def setUp(self):
- super().setUp()
- for variable, value in self.variables.items():
- self._add_variable_cleanup(variable)
- if value is None:
- self.environment.unset_initctl_env_var(
- variable, global_=self.global_)
- else:
- self.environment.set_initctl_env_var(
- variable, value, global_=self.global_)
-
- def _add_variable_cleanup(self, variable):
- if self.environment.is_initctl_env_var_set(
- variable, global_=self.global_):
- original_value = self.environment.get_initctl_env_var(
- variable, global_=self.global_)
- self.addCleanup(
- self.environment.set_initctl_env_var,
- variable,
- original_value,
- global_=self.global_)
- else:
- self.addCleanup(
- self.environment.unset_initctl_env_var,
- variable,
- global_=self.global_)
-
-
class FakeHome(fixtures.Fixture):
# We copy the Xauthority file to allow executions using XVFB. If it is not
@@ -210,10 +171,6 @@
self.directory = self._make_directory_if_not_specified()
if self.should_copy_xauthority_file:
self._copy_xauthority_file(self.directory)
- # We patch both environment variables so it works on the desktop and on
- # the phone.
- self.useFixture(
- InitctlEnvironmentVariable(HOME=self.directory))
self.useFixture(
fixtures.EnvironmentVariable('HOME', newvalue=self.directory))
=== modified file 'tests/autopilot/ubuntuuitoolkit/tests/__init__.py'
--- tests/autopilot/ubuntuuitoolkit/tests/__init__.py 2015-12-09 14:21:53 +0000
+++ tests/autopilot/ubuntuuitoolkit/tests/__init__.py 2017-01-18 15:58:41 +0000
@@ -16,6 +16,7 @@
"""Ubuntu UI Toolkit autopilot tests."""
+import fixtures
import os
import tempfile
@@ -106,9 +107,7 @@
desktop_file_name = os.path.basename(
fake_application.desktop_file_path)
application_name, _ = os.path.splitext(desktop_file_name)
- self.app = self.launch_upstart_application(
- application_name,
- emulator_base=ubuntuuitoolkit.UbuntuUIToolkitCustomProxyObjectBase)
+ self.app = self.launch_test_application(application_name)
def use_local_modules(self, local_modules_path):
env_vars = [
@@ -116,10 +115,9 @@
'QML2_IMPORT_PATH',
'UBUNTU_UI_TOOLKIT_THEMES_PATH'
]
- kwargs = {'global_': True}
for env in env_vars:
- kwargs[env] = local_modules_path
- self.useFixture(fixture_setup.InitctlEnvironmentVariable(**kwargs))
+ self.useFixture(fixtures.EnvironmentVariable(env,
+ local_modules_path))
class QMLStringAppTestCase(UbuntuUIToolkitWithFakeAppRunningTestCase):
=== modified file 'tests/autopilot/ubuntuuitoolkit/tests/components/test_units.py'
--- tests/autopilot/ubuntuuitoolkit/tests/components/test_units.py 2015-04-14 21:02:06 +0000
+++ tests/autopilot/ubuntuuitoolkit/tests/components/test_units.py 2017-01-18 15:58:41 +0000
@@ -23,10 +23,7 @@
import fixtures
-from ubuntuuitoolkit import (
- fixture_setup,
- units
-)
+from ubuntuuitoolkit import units
logger = logging.getLogger(__name__)
@@ -52,8 +49,6 @@
def setUp(self):
self.useFixture(fixtures.EnvironmentVariable(
'GRID_UNIT_PX', self.grid_unit_px))
- self.useFixture(fixture_setup.InitctlEnvironmentVariable(
- global_=True, GRID_UNIT_PX=self.grid_unit_px))
super().setUp()
def test_gu(self):
=== modified file 'tests/autopilot/ubuntuuitoolkit/tests/gallery/__init__.py'
--- tests/autopilot/ubuntuuitoolkit/tests/gallery/__init__.py 2016-08-10 14:05:48 +0000
+++ tests/autopilot/ubuntuuitoolkit/tests/gallery/__init__.py 2017-01-18 15:58:41 +0000
@@ -17,7 +17,6 @@
"""Tests for the Ubuntu UI Toolkit Gallery"""
import os
-import shutil
from autopilot.matchers import Eventually
from testtools.matchers import Equals
=== removed file 'tests/autopilot/ubuntuuitoolkit/tests/test_environment.py'
--- tests/autopilot/ubuntuuitoolkit/tests/test_environment.py 2014-08-29 16:12:02 +0000
+++ tests/autopilot/ubuntuuitoolkit/tests/test_environment.py 1970-01-01 00:00:00 +0000
@@ -1,89 +0,0 @@
-# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
-#
-# Copyright (C) 2014 Canonical Ltd.
-#
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU Lesser General Public License as published by
-# the Free Software Foundation; version 3.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public License
-# along with this program. If not, see <http://www.gnu.org/licenses/>.
-
-import uuid
-
-import testtools
-
-from ubuntuuitoolkit import environment
-
-
-class InitctlEnvironmentVariableTestCase(testtools.TestCase):
-
- def test_is_environment_variable_set_with_unset_variable(self):
- """Test that is_initctl_env_var_set returns False for unset vars."""
- variable = 'I do not exist {}'.format(uuid.uuid1())
- self.assertFalse(environment.is_initctl_env_var_set(variable))
-
- def test_is_environment_variable_set_with_set_variable(self):
- """Test that is_initctl_env_var_set returns True for existing vars."""
- variable = 'Test variable to set {}'.format(uuid.uuid1())
- self.addCleanup(environment.unset_initctl_env_var, variable)
-
- environment.set_initctl_env_var(variable, 'dummy')
-
- self.assertTrue(environment.is_initctl_env_var_set(variable))
-
- def test_get_environment_variable(self):
- """Test that get_initctl_env_var returns the right value."""
- variable = 'Test variable to get {}'.format(uuid.uuid1())
- self.addCleanup(environment.unset_initctl_env_var, variable)
- environment.set_initctl_env_var(variable, 'test value')
-
- self.assertEqual(
- 'test value', environment.get_initctl_env_var(variable))
-
- def test_unset_environment_variable(self):
- """Test that unset_initctl_env_var removes the variable."""
- variable = 'Test variable to unset {}'.format(uuid.uuid1())
- environment.set_initctl_env_var(variable, 'dummy')
-
- environment.unset_initctl_env_var(variable)
-
- self.assertFalse(environment.is_initctl_env_var_set(variable))
-
- def test_unset_environment_variable_with_unset_variable(self):
- """Test that unset_initctl_env_var does nothing with unset var."""
- variable = 'I do not exist {}'.format(uuid.uuid1())
-
- environment.unset_initctl_env_var(variable)
-
- self.assertFalse(environment.is_initctl_env_var_set(variable))
-
- def test_is_global_environment_variable_set_with_unset_variable(self):
- """Test is_initctl_env_var_set returns False for unset global vars."""
- variable = 'I do not exist global {}'.format(uuid.uuid1())
-
- self.assertFalse(environment.is_initctl_env_var_set(
- variable, global_=True))
-
- def test_get_global_environment_variable(self):
- """Test that get_initctl_env_var returns the right global value."""
- variable = 'Test variable to get {}'.format(uuid.uuid1())
- self.addCleanup(
- environment.unset_initctl_env_var, variable, global_=True)
- environment.set_initctl_env_var(variable, 'test value', global_=True)
-
- self.assertEqual(
- 'test value',
- environment.get_initctl_env_var(variable, global_=True))
-
- def test_unset_global_environment_variable(self):
- """Test that unset_initctl_env_var removes the global variable."""
- variable = 'Test variable to unset {}'.format(uuid.uuid1())
-
- environment.set_initctl_env_var(variable, 'dummy', global_=True)
- environment.unset_initctl_env_var(variable, global_=True)
=== modified file 'tests/autopilot/ubuntuuitoolkit/tests/test_fixture_setup.py'
--- tests/autopilot/ubuntuuitoolkit/tests/test_fixture_setup.py 2015-07-09 21:55:03 +0000
+++ tests/autopilot/ubuntuuitoolkit/tests/test_fixture_setup.py 2017-01-18 15:58:41 +0000
@@ -19,18 +19,16 @@
import tempfile
from unittest import mock
-import testscenarios
import testtools
from autopilot import (
display,
- introspection,
platform,
testcase as autopilot_testcase
)
from autopilot.matchers import Eventually
from testtools.matchers import Contains, Equals, FileExists, Not
-from ubuntuuitoolkit import base, environment, fixture_setup, tests
+from ubuntuuitoolkit import base, fixture_setup, tests
class FakeApplicationTestCase(testtools.TestCase):
@@ -190,9 +188,6 @@
url_dispatcher_protocols=['testprotocol'])
self.useFixture(fake_application)
- self.useFixture(fixture_setup.InitctlEnvironmentVariable(
- QT_LOAD_TESTABILITY=1))
-
self.addCleanup(
subprocess.check_output,
['ubuntu-app-stop', fake_application.application_name])
@@ -203,134 +198,11 @@
pid = int(subprocess.check_output(
['ubuntu-app-pid', fake_application.application_name]).strip())
- application = introspection.get_proxy_object_for_existing_process(
- pid=pid)
-
- # We can select a component from the application.
- application.select_single('Label', objectName='testLabel')
-
-
-class InitctlEnvironmentVariableTestCase(testscenarios.TestWithScenarios):
-
- scenarios = [
- ('global_variable', {'global_': True}),
- ('local_variable', {'global_': False})
- ]
-
- def set_original_value(self, value):
- self.addCleanup(
- environment.unset_initctl_env_var, 'testenvvarforfixture',
- global_=self.global_)
- environment.set_initctl_env_var('testenvvarforfixture',
- value, global_=self.global_)
-
- def create_fixture(self, value):
- self.initctl_env_var = fixture_setup.InitctlEnvironmentVariable(
- testenvvarforfixture=value, global_=self.global_)
-
- def assertValueIs(self, expected_value):
- self.assertEqual(
- expected_value,
- environment.get_initctl_env_var(
- 'testenvvarforfixture', global_=self.global_))
-
- def assertVariableIsNotSet(self):
- self.assertFalse(
- environment.is_initctl_env_var_set(
- 'testenvvarforfixture', global_=self.global_))
-
- def assertTestIsSuccessful(self, expected_value, test_name):
- result = testtools.TestResult()
-
- class TestWithInitctlEnvVar(testtools.TestCase):
- def setUp(inner):
- super().setUp()
- inner.useFixture(self.initctl_env_var)
-
- def test_value_set(inner):
- self.assertValueIs(expected_value)
-
- def test_variable_not_set(inner):
- self.assertVariableIsNotSet()
-
- TestWithInitctlEnvVar(test_name).run(result)
- self.assertTrue(
- result.wasSuccessful(), 'Failed to set the environment variable.')
-
- def test_use_initctl_environment_variable_to_set_unexisting_variable(self):
- """Test the initctl env var fixture when the var is unset.
-
- During the test, the new value must be in place.
- After the test, the variable must be unset again.
-
- """
- self.create_fixture('test value')
- self.assertTestIsSuccessful('test value', 'test_value_set')
- self.assertVariableIsNotSet()
-
- def test_use_initctl_environment_variable_to_set_existing_variable(self):
- """Test the initctl env var fixture when the var is unset.
-
- During the test, the new value must be in place.
- After the test, the old value must be set again.
-
- """
- self.set_original_value('original test value')
- self.create_fixture('new test value')
- self.assertTestIsSuccessful('new test value', 'test_value_set')
- self.assertValueIs('original test value')
-
- def test_use_initctl_environment_variable_to_unset_existing_variable(self):
- """Test the initctl env var fixture to unset a variable.
-
- During the test, the variable must be unset.
- After the test, the old value must be set again.
-
- """
- self.set_original_value('original test value')
- self.create_fixture(None)
- self.assertTestIsSuccessful(None, 'test_variable_not_set')
- self.assertValueIs('original test value',)
-
- def test_use_initctl_environment_variable_to_unset_nonexisting_variable(
- self):
- """Test the initctl env var fixture to unset a variable.
-
- During the test, the variable must be unset.
- After the test, the variable must remain unset.
-
- """
- self.create_fixture(None)
- self.assertTestIsSuccessful(None, 'test_variable_not_set')
- self.assertVariableIsNotSet()
+ self.assertGreater(pid, 0)
class FakeHomeTestCase(testtools.TestCase):
- def test_fake_home_fixture_patches_initctl_env_var(self):
- original_home = environment.get_initctl_env_var('HOME')
- fake_home = original_home + 'fake'
- result = testtools.TestResult()
-
- def inner_test():
- class TestWithFakeHome(testtools.TestCase):
- def test_it(self):
- fake_home_fixture = fixture_setup.FakeHome(fake_home)
- fake_home_fixture.should_copy_xauthority_file = False
- self.useFixture(fake_home_fixture)
- self.assertEqual(
- fake_home, environment.get_initctl_env_var('HOME'))
- return TestWithFakeHome('test_it')
-
- inner_test().run(result)
-
- self.assertTrue(
- result.wasSuccessful(),
- 'Failed to fake the home: {}'.format(result.errors))
- self.assertEqual(
- original_home,
- environment.get_initctl_env_var('HOME'))
-
def test_fake_home_fixture_patches_env_var(self):
original_home = os.environ.get('HOME')
fake_home = tempfile.gettempdir()
=== modified file 'tests/autopilot/ubuntuuitoolkit/units.py'
--- tests/autopilot/ubuntuuitoolkit/units.py 2015-02-07 05:03:06 +0000
+++ tests/autopilot/ubuntuuitoolkit/units.py 2017-01-18 15:58:41 +0000
@@ -18,8 +18,6 @@
import os
-from ubuntuuitoolkit import environment
-
ENV_GRID_UNIT_PX = 'GRID_UNIT_PX'
DEFAULT_GRID_UNIT_PX = 8
@@ -27,9 +25,6 @@
def get_grid_unit():
grid_unit_px = os.environ.get(ENV_GRID_UNIT_PX, None)
- if not grid_unit_px and environment.is_initctl_env_var_set(
- ENV_GRID_UNIT_PX):
- grid_unit_px = environment.get_initctl_env_var(ENV_GRID_UNIT_PX)
return float(grid_unit_px or DEFAULT_GRID_UNIT_PX)
References