Merge lp:~canonical-platform-qa/ubuntu-system-tests/spike_manage_test_metadata into lp:ubuntu-system-tests

Proposed by Sergio Cazzolato
Status: Work in progress
Proposed branch: lp:~canonical-platform-qa/ubuntu-system-tests/spike_manage_test_metadata
Merge into: lp:ubuntu-system-tests
Diff against target: 172 lines (+156/-0)
3 files modified
ubuntu_system_tests/external_tests/suites/__init__.py (+116/-0)
ubuntu_system_tests/external_tests/suites/dialer_tests.json (+26/-0)
ubuntu_system_tests/external_tests/suites/webbrowser_app.json (+14/-0)
To merge this branch: bzr merge lp:~canonical-platform-qa/ubuntu-system-tests/spike_manage_test_metadata
Reviewer Review Type Date Requested Status
PS Jenkins bot continuous-integration Needs Fixing
Canonical Platform QA Team Pending
Review via email: mp+261791@code.launchpad.net

Description of the change

Experimental approach to manage test metadata

This approach is similar to the one that TestNG uses defining groups of tests/testsuites.

The idea is to manage all the metadata of the test cases in a json file in a similar way that the Richards implementation.

This piece of code is not the whole implementation, it is just what I would change.

---------------
HOW TO TEST IT:
---------------

import suites
man = suites.TestMetadataManager()

print(man.get_tests_and_dependencies(group='Web'))

print(man.get_tests_and_dependencies()

print(man.get_tests_and_dependencies(suite='dialer_app', group='Telephony'))

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :

FAILED: Continuous integration, rev:129
No commit message was specified in the merge proposal. Click on the following link and set the commit message (if you want a jenkins rebuild you need to trigger it yourself):
https://code.launchpad.net/~canonical-platform-qa/ubuntu-system-tests/spike_manage_test_metadata/+merge/261791/+edit-commit-message

http://s-jenkins.ubuntu-ci:8080/job/ubuntu-sanity-tests-ci/335/
Executed test runs:
    SUCCESS: http://s-jenkins.ubuntu-ci:8080/job/ubuntu-sanity-tests-wily-amd64-ci/106
    SUCCESS: http://s-jenkins.ubuntu-ci:8080/job/ubuntu-sanity-tests-wily-armhf-ci/107
    SUCCESS: http://s-jenkins.ubuntu-ci:8080/job/ubuntu-sanity-tests-wily-i386-ci/106

Click here to trigger a rebuild:
http://s-jenkins.ubuntu-ci:8080/job/ubuntu-sanity-tests-ci/335/rebuild

review: Needs Fixing (continuous-integration)
Revision history for this message
Brendan Donegan (brendan-donegan) wrote :

Setting back to WIP, please reset to needs review if you still want it to land

Unmerged revisions

129. By Sergio Cazzolato

experimental approach to manage test metadata

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added directory 'ubuntu_system_tests/external_tests/suites'
2=== added file 'ubuntu_system_tests/external_tests/suites/__init__.py'
3--- ubuntu_system_tests/external_tests/suites/__init__.py 1970-01-01 00:00:00 +0000
4+++ ubuntu_system_tests/external_tests/suites/__init__.py 2015-06-11 22:56:31 +0000
5@@ -0,0 +1,116 @@
6+# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
7+
8+#
9+# Ubuntu System Tests
10+# Copyright (C) 2015 Canonical
11+#
12+# This program is free software: you can redistribute it and/or modify
13+# it under the terms of the GNU General Public License as published by
14+# the Free Software Foundation, either version 3 of the License, or
15+# (at your option) any later version.
16+#
17+# This program is distributed in the hope that it will be useful,
18+# but WITHOUT ANY WARRANTY; without even the implied warranty of
19+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20+# GNU General Public License for more details.
21+#
22+# You should have received a copy of the GNU General Public License
23+# along with this program. If not, see <http://www.gnu.org/licenses/>.
24+#
25+
26+import json
27+import os
28+
29+
30+def get_external_suite_dir_path():
31+ """Returns path of the directory containing external test suites"""
32+ return os.path.dirname(__file__)
33+
34+
35+def test_metadata_set_decoder(dic):
36+ return TestMetadataSet(dic['name'],
37+ dic['depends'],
38+ dic['groups'],
39+ dic['tests'])
40+
41+
42+def test_metadata_decoder(dic):
43+ return TestMetadata(dic['name'],
44+ dic['depends'],
45+ dic['groups'])
46+
47+
48+class TestMetadataManager():
49+
50+ def __init__(self):
51+ self.test_sets = []
52+ self._load_external_tests()
53+
54+ def _load_set(self, path):
55+ with open(path) as f:
56+ test_set_dict = json.load(f)
57+ self.test_sets.append(test_metadata_set_decoder(test_set_dict))
58+
59+ def _load_external_tests(self):
60+ external_path = get_external_suite_dir_path()
61+ json_files = [f for f in os.listdir(external_path) if
62+ os.path.isfile(os.path.join(external_path, f)) and
63+ f.endswith('.json')]
64+
65+ for json_file in json_files:
66+ self._load_set(os.path.join(external_path, json_file))
67+
68+ def _get_test_set(self, name):
69+ for test_set in self.test_sets:
70+ if name == test_set.name:
71+ return test_set
72+
73+ def get_tests_and_dependencies(self, group=None, suite=None):
74+ if suite:
75+ self._get_test_set(suite).get_tests_and_dependencies(group)
76+
77+ tests = []
78+ dependencies = []
79+ for test_set in self.test_sets:
80+ curr_tests, curr_deps = test_set.get_tests_and_dependencies(group)
81+ tests += curr_tests
82+ dependencies += curr_deps
83+
84+ return tests, list(set(dependencies))
85+
86+
87+class TestMetadataSet():
88+
89+ def __init__(self, name, depends, groups, tests):
90+ self.name = name or ""
91+ self.depends = depends or []
92+ self.groups = groups
93+ self.tests = [test_metadata_decoder(test) for test in tests] or []
94+
95+ def get_tests_and_dependencies(self, group=None):
96+ if not group or group in self.groups:
97+ return self.get_all_tests_and_dependencies()
98+
99+ dependencies = []
100+ for test in self.tests:
101+ if not group or group in test.groups:
102+ dependencies += test.depends
103+
104+ return [test.name for test in self.tests if not group or group in
105+ test.groups], list(set(dependencies))
106+
107+ def get_all_tests_and_dependencies(self):
108+ dependencies = []
109+ for test in self.tests:
110+ dependencies += test.depends
111+
112+ return [test.name for test in self.tests], list(set(self.depends +
113+ dependencies))
114+
115+
116+class TestMetadata():
117+
118+ def __init__(self, name, depends, groups):
119+ self.name = name or ""
120+ self.depends = depends or []
121+ self.groups = groups or []
122
123=== added file 'ubuntu_system_tests/external_tests/suites/dialer_tests.json'
124--- ubuntu_system_tests/external_tests/suites/dialer_tests.json 1970-01-01 00:00:00 +0000
125+++ ubuntu_system_tests/external_tests/suites/dialer_tests.json 2015-06-11 22:56:31 +0000
126@@ -0,0 +1,26 @@
127+{
128+ "name": "dialer_app",
129+ "depends": ["dialer-app-autopilot", "dialer-app"],
130+ "groups": [
131+ "Telephony"
132+ ],
133+ "tests": [
134+ {
135+ "name": "dialer_app.tests.test_calls",
136+ "depends": [],
137+ "groups": [
138+
139+ ]
140+ },
141+ {
142+ "name": "dialer_app.tests.test_dialer",
143+ "depends": [],
144+ "groups": [
145+
146+ ]
147+ }
148+ ]
149+}
150+
151+
152+
153
154=== added file 'ubuntu_system_tests/external_tests/suites/webbrowser_app.json'
155--- ubuntu_system_tests/external_tests/suites/webbrowser_app.json 1970-01-01 00:00:00 +0000
156+++ ubuntu_system_tests/external_tests/suites/webbrowser_app.json 2015-06-11 22:56:31 +0000
157@@ -0,0 +1,14 @@
158+{
159+ "name": "webbrowser_app",
160+ "depends": ["webbrowser-app-autopilot"],
161+ "groups": [
162+ "Web"
163+ ],
164+ "tests": [
165+ {
166+ "name": "webbrowser_app.tests.test_backforward.TestBackForward.test_go_forward_after_going_back",
167+ "depends": [],
168+ "groups": []
169+ }
170+ ]
171+}
172\ No newline at end of file

Subscribers

People subscribed via source and target branches

to all changes: