Merge lp:~dpm/ubuntu-filemanager-app/run-ap-from-out-of-source-build into lp:ubuntu-filemanager-app

Proposed by David Planella
Status: Merged
Merged at revision: 253
Proposed branch: lp:~dpm/ubuntu-filemanager-app/run-ap-from-out-of-source-build
Merge into: lp:ubuntu-filemanager-app
Prerequisite: lp:~dpm/ubuntu-filemanager-app/fix-desktop-run
Diff against target: 155 lines (+132/-2)
2 files modified
tests/autopilot/filemanager/CMakePluginParser.py (+120/-0)
tests/autopilot/filemanager/tests/__init__.py (+12/-2)
To merge this branch: bzr merge lp:~dpm/ubuntu-filemanager-app/run-ap-from-out-of-source-build
Reviewer Review Type Date Requested Status
Ubuntu Phone Apps Jenkins Bot continuous-integration Approve
Leo Arias Pending
Nicholas Skaggs Pending
Review via email: mp+217510@code.launchpad.net

Commit message

Enable detection of the build dir and running the autopilot tests from there.

Description of the change

Enable detection of the build dir and running the autopilot tests from there.

The idea is that we can dogfood the tools we're providing to developers, thus this branch brings the ability of building the app with Qt Creator and then running the AP tests from that same build directory.

To post a comment you must log in.
Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Needs Fixing (continuous-integration)
175. By David Planella

Fix pep8 warnings

Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Nicholas Skaggs (nskaggs) wrote :

Thanks David, this makes it easier to review.

Revision history for this message
Nicholas Skaggs (nskaggs) wrote :

David, I need Leo's feedback here again, but initially speaking about this, I think we would rather see an argument to autopilot, rather than the test parse something. Leo should have a bug around for this. I don't want to let this languish, so certainly we can land something as a stop-gap if needed.

Revision history for this message
David Planella (dpm) wrote :

The issue with an argument is that is less automated (i.e. with this branch I can just run autopilot with the right build dir being auto-detected, whereas with an argument I'd have to look for the build dir and pass it to AP).

However, if you guys have got a better solution that supersedes this branch, happy to go with that too.

Revision history for this message
David Planella (dpm) wrote :

I'll mark this as Work in progress, to drop the dependency on python-lxml, which is not installed in the phone images.

Revision history for this message
Leo Arias (elopio) wrote :

> The issue with an argument is that is less automated (i.e. with this branch I
> can just run autopilot with the right build dir being auto-detected, whereas
> with an argument I'd have to look for the build dir and pass it to AP).

What I think is that we shouldn't call autopilot run directly if we are developing the app. IMO, we should call the cmake autopilot tasks.
I'm also thinking about more complex scenarios that need to start fake servers or set up fake services. For example, on the click scope we run:
make test-click-scope-autopilot-fake-servers
And it takes care of passing the right variables to the scripts to find the compiled scope and to set the right addresses for the servers.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file 'tests/autopilot/filemanager/CMakePluginParser.py'
2--- tests/autopilot/filemanager/CMakePluginParser.py 1970-01-01 00:00:00 +0000
3+++ tests/autopilot/filemanager/CMakePluginParser.py 2014-04-29 12:03:28 +0000
4@@ -0,0 +1,120 @@
5+# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
6+#
7+# Copyright (C) 2014 Canonical Ltd.
8+#
9+# This program is free software; you can redistribute it and/or modify
10+# it under the terms of the GNU Lesser General Public License as published by
11+# the Free Software Foundation; version 3.
12+#
13+# This program is distributed in the hope that it will be useful,
14+# but WITHOUT ANY WARRANTY; without even the implied warranty of
15+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+# GNU Lesser General Public License for more details.
17+#
18+# You should have received a copy of the GNU Lesser General Public License
19+# along with this program. If not, see <http://www.gnu.org/licenses/>.
20+#
21+# Author:
22+# David Planella <david.planella@ubuntu.com>
23+
24+"""
25+This module parses a configuration file from the Qt Creator's CMake plugin and
26+enables programmatical read-only access to several of its configuration options
27+"""
28+
29+import sys
30+from lxml import etree
31+
32+
33+class CMakePluginParseError(Exception):
34+ """
35+ Custom exception for errors during the parsing of a
36+ CMakeLists.txt.user file
37+ """
38+ def __init__(self, message):
39+ Exception.__init__(self, message)
40+
41+
42+class CMakePluginParser(object):
43+ """
44+ Parses a CMake plugin's config file and provides R/O access to its
45+ configuration options """
46+
47+ def __init__(self, cmakelists_usr_file='CMakeLists.txt.user'):
48+ self.usr_file = cmakelists_usr_file
49+
50+ try:
51+ self.info = etree.parse(self.usr_file)
52+ except:
53+ sys.stderr.write("Could not open the given " +
54+ "CMakeLists.txt.user file: " + self.info)
55+ raise
56+
57+ def _get_active_build_target(self):
58+ """
59+ Return the active build target from the current project in Qt Creator
60+ """
61+
62+ try:
63+ active_build_target_nr = self.info.xpath(
64+ "./data/variable" +
65+ "[text()='ProjectExplorer.Project.ActiveTarget']" +
66+ "/../value")[0].text
67+ except:
68+ raise CMakePluginParseError("Could not find the active build " +
69+ "target in the CMake plugin's config")
70+
71+ active_build_target = "ProjectExplorer.Project.Target." + \
72+ active_build_target_nr
73+
74+ return active_build_target
75+
76+ def _get_active_build_config(self, active_build_target):
77+ """Return the active build config from the active build targed"""
78+
79+ try:
80+ active_build_config_nr = self.info.xpath(
81+ "./data/variable[text()='{0}']".format(active_build_target) +
82+ "/..//value[@key="
83+ "'ProjectExplorer.Target.ActiveBuildConfiguration']")[0].text
84+ except:
85+ raise CMakePluginParseError("Could not find the active build " +
86+ "target's active build config " +
87+ "in the CMake plugin's config")
88+
89+ active_build_config = "ProjectExplorer.Target.BuildConfiguration." + \
90+ active_build_config_nr
91+
92+ return active_build_config
93+
94+ def _get_active_build_config_path(self):
95+ """Return the active build config's absolute path"""
96+
97+ active_build_target = self._get_active_build_target()
98+ active_build_config = \
99+ self._get_active_build_config(active_build_target)
100+
101+ try:
102+ active_build_config_node = self.info.xpath(
103+ "./data/variable[text()='{0}']".format(active_build_target) +
104+ "/..//valuemap[@key='{0}']".format(active_build_config))[0]
105+ except:
106+ raise CMakePluginParseError("Could not find the active " +
107+ "build config's node " +
108+ "in the CMake plugin's config")
109+
110+ try:
111+ active_build_config_path = active_build_config_node.xpath(
112+ "./value[@key=" +
113+ "'ProjectExplorer.BuildConfiguration.BuildDirectory']")[0].text
114+ except:
115+ raise CMakePluginParseError("Could not find the active build " +
116+ "directory in the CMake plugin's " +
117+ "config")
118+
119+ return active_build_config_path
120+
121+ @property
122+ def active_build_dir(self):
123+ """Return the active build config's directory as an absolute path"""
124+ return self._get_active_build_config_path()
125
126=== modified file 'tests/autopilot/filemanager/tests/__init__.py'
127--- tests/autopilot/filemanager/tests/__init__.py 2014-04-29 12:03:28 +0000
128+++ tests/autopilot/filemanager/tests/__init__.py 2014-04-29 12:03:28 +0000
129@@ -13,7 +13,7 @@
130 import logging
131
132 import fixtures
133-from filemanager import emulators
134+from filemanager import emulators, CMakePluginParser
135
136 from autopilot.input import Mouse, Touch, Pointer
137 from autopilot.platform import model
138@@ -73,7 +73,17 @@
139 self.app = self.launch_test_click()
140
141 def _get_build_dir(self):
142- build_dir = self.source_dir
143+ """
144+ Returns the build dir after having parsed the CMake config file
145+ generated by Qt Creator. If it cannot find it or it cannot be parsed,
146+ an in-tree build is assumed and thus returned.
147+ """
148+ try:
149+ cmake_config = CMakePluginParser.CMakePluginParser(os.path.join(
150+ self.source_dir, 'CMakeLists.txt.user'))
151+ build_dir = cmake_config.active_build_dir
152+ except:
153+ build_dir = self.source_dir
154
155 return build_dir
156

Subscribers

People subscribed via source and target branches