~nik90/ubuntu-clock-app/new-bottom-edge

« back to all changes in this revision

Viewing changes to tests/autopilot/ubuntu_clock_app/tests/__init__.py

  • Committer: Nekhelesh Ramananthan
  • Date: 2016-02-25 23:10:10 UTC
  • mfrom: (442.2.1 trunk)
  • Revision ID: krnekhelesh@gmail.com-20160225231010-xb8ie0ruwmfhmq4u
MergedĀ lp:ubuntu-clock-app

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
from ubuntuuitoolkit import base
31
31
 
32
32
import ubuntu_clock_app
33
 
from ubuntu_clock_app import fixture_setup, CMakePluginParser
34
33
 
35
34
logger = logging.getLogger(__name__)
36
35
 
42
41
 
43
42
    """
44
43
 
 
44
    # Source built locally paths
 
45
    local_location = os.path.dirname(os.path.dirname(os.getcwd()))
 
46
    local_build_location = os.path.join(local_location, 'builddir')
 
47
    local_build_location_qml = os.path.join(
 
48
        local_location, 'app/ubuntu-clock-app.qml')
 
49
    #local_build_location_binary = os.path.join(local_build_location, 'app')
 
50
    local_build_location_backend = os.path.join(local_build_location, 'backend')
 
51
 
 
52
 
 
53
    # Source built with SDK paths
 
54
    sdk_build_location = os.path.join(os.path.dirname(local_location),
 
55
                                      os.path.basename(local_location)
 
56
                                      + '-build')
 
57
    sdk_build_location_qml = os.path.join(
 
58
        local_location, 'app/ubuntu-clock-app.qml')
 
59
    #sdk_build_location_binary = os.path.join(sdk_build_location, 'app/ubuntu-clock-app')
 
60
    sdk_build_location_backend = os.path.join(sdk_build_location, 'backend')
 
61
 
 
62
    # Installed binary paths
 
63
    #installed_location_binary = '/usr/bin/ubuntu-clock-app'
 
64
    installed_location_qml = '/usr/share/ubuntu-clock-app/ubuntu-clock-app.qml'
 
65
    installed_location_backend = ""
 
66
    if glob.glob('/usr/lib/*/qt5/qml/ClockApp'):
 
67
        self.installed_location_backend = \
 
68
            glob.glob('/usr/lib/*/qt5/qml/ClockApp')[0]
 
69
 
45
70
    def setUp(self):
46
 
        # setup paths
47
 
        self.binary = 'ubuntu-clock-app'
48
 
        self.source_dir = os.path.dirname(
49
 
            os.path.dirname(os.path.abspath('.')))
50
 
        self.build_dir = self._get_build_dir()
51
 
 
52
 
        self.local_location = self.source_dir
53
 
        self.local_location_qml = os.path.join(self.source_dir,
54
 
                                               'app', self.binary + '.qml')
55
 
 
56
 
        self.local_location_backend = os.path.join(self.build_dir, 'backend')
57
 
 
58
 
        self.installed_location_backend = ""
59
 
        if glob.glob('/usr/lib/*/qt5/qml/ClockApp'):
60
 
            self.installed_location_backend = \
61
 
                glob.glob('/usr/lib/*/qt5/qml/ClockApp')[0]
62
 
        self.installed_location_qml = \
63
 
            '/usr/share/ubuntu-clock-app/ubuntu-clock-app.qml'
64
 
 
65
71
        self.sqlite_dir = os.path.expanduser(
66
72
            "~/.local/share/com.ubuntu.clock")
67
73
        self.backup_dir = self.sqlite_dir + ".backup"
70
76
        self.temp_move_sqlite_db()
71
77
        self.addCleanup(self.restore_sqlite_db)
72
78
 
73
 
        # setup fixtures and launcher
74
 
        self.useFixture(fixture_setup.LocationServiceTestEnvironment())
75
 
        self.useFixture(fixtures.EnvironmentVariable('LC_ALL', newvalue='C'))
 
79
        # setup launcher
76
80
        self.launcher, self.test_type = self.get_launcher_and_type()
77
81
 
78
82
        # launch application under introspection
80
84
        self.app = ubuntu_clock_app.ClockApp(self.launcher(), self.test_type)
81
85
 
82
86
    def get_launcher_and_type(self):
83
 
        if os.path.exists(self.local_location_backend):
 
87
        if os.path.exists(self.local_build_location_backend):
84
88
            launcher = self.launch_test_local
85
89
            test_type = 'local'
 
90
        elif os.path.exists(self.sdk_build_location_backend):
 
91
            launcher = self.launch_test_sdk
 
92
            test_type = 'sdk'
86
93
        elif os.path.exists(self.installed_location_backend):
87
94
            launcher = self.launch_test_installed
88
95
            test_type = 'deb'
95
102
    def launch_test_local(self):
96
103
        return self.launch_test_application(
97
104
            base.get_qmlscene_launch_command(),
98
 
            self.local_location_qml,
99
 
            "-I", self.local_location_backend,
 
105
            self.local_build_location_qml,
 
106
            "-I", self.local_build_location_backend,
 
107
            app_type='qt',
 
108
            emulator_base=ubuntuuitoolkit.UbuntuUIToolkitCustomProxyObjectBase)
 
109
 
 
110
    @autopilot_logging.log_action(logger.info)
 
111
    def launch_test_sdk(self):
 
112
        return self.launch_test_application(
 
113
            base.get_qmlscene_launch_command(),
 
114
            self.sdk_build_location_qml,
 
115
            "-I", self.sdk_build_location_backend,
100
116
            app_type='qt',
101
117
            emulator_base=ubuntuuitoolkit.UbuntuUIToolkitCustomProxyObjectBase)
102
118
 
143
159
                shutil.move(self.backup_dir, self.sqlite_dir)
144
160
            except:
145
161
                logger.error("Failed to restore database")
146
 
 
147
 
    def _get_build_dir(self):
148
 
        """
149
 
        Returns the build dir after having parsed the CMake config file
150
 
        generated by Qt Creator. If it cannot find it or it cannot be parsed,
151
 
        an in-tree build is assumed and thus returned.
152
 
        """
153
 
        try:
154
 
            cmake_config = CMakePluginParser.CMakePluginParser(os.path.join(
155
 
                self.source_dir, 'CMakeLists.txt.user'))
156
 
            build_dir = cmake_config.active_build_dir
157
 
        except:
158
 
            logger.error("Error parsing CMakeLists.txt.user %s",
159
 
                         sys.exc_info()[0])
160
 
            build_dir = os.path.join(self.source_dir, 'builddir')
161
 
 
162
 
        return build_dir