Merge lp:~canonical-platform-qa/ubuntu-ui-toolkit/grid_units into lp:ubuntu-ui-toolkit/staging

Proposed by Leo Arias on 2015-02-06
Status: Merged
Approved by: Tim Peeters on 2015-04-13
Approved revision: 1424
Merged at revision: 1473
Proposed branch: lp:~canonical-platform-qa/ubuntu-ui-toolkit/grid_units
Merge into: lp:ubuntu-ui-toolkit/staging
Diff against target: 108 lines (+99/-0)
2 files modified
tests/autopilot/ubuntuuitoolkit/tests/components/test_units.py (+61/-0)
tests/autopilot/ubuntuuitoolkit/units.py (+38/-0)
To merge this branch: bzr merge lp:~canonical-platform-qa/ubuntu-ui-toolkit/grid_units
Reviewer Review Type Date Requested Status
PS Jenkins bot continuous-integration Needs Fixing on 2015-04-13
Tim Peeters Approve on 2015-04-13
Leo Arias (community) Approve on 2015-04-13
Zsombor Egri (community) 2015-02-06 Needs Fixing on 2015-02-09
Review via email: mp+248980@code.launchpad.net

Commit Message

Added a grids unit helper for autopilot tests.

Description of the Change

As suggested by timp, in the autopilot tests we should use grid units instead of pixels. That is correct, and it will make the math easier. This is the helper to start doing it in my following branch.

To post a comment you must log in.
Zsombor Egri (zsombi) wrote :

Small comment underneath

review: Needs Fixing
Tim Peeters (tpeeters) wrote :

The tests don't use features of the MainView, so you could instead use a simple Item as the root.

Brendan Donegan (brendan-donegan) wrote :

Just a note that I doubt an autopilot test is the best way to test these new functions - a python unit test seems more appropriate - after all we only care that those functions return the correct values, everything else is incidental.

Leo Arias (elopio) wrote :

I thought about that too, but having these tests failing on mako shows it might not be a good idea.
I can easily write a test that checks that the returned values are right, but we are missing something that makes the high level tests fail. We need to first find what the issue is on the high level test, and write a low level test for it.

Leo Arias (elopio) wrote :

Ran the tests, looks good. Thanks for the digging into this.

review: Approve
Tim Peeters (tpeeters) wrote :

Looks good!

review: Approve
1424. By Brendan Donegan on 2015-04-13

Fix flake8 issues

review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file 'tests/autopilot/ubuntuuitoolkit/tests/components/test_units.py'
2--- tests/autopilot/ubuntuuitoolkit/tests/components/test_units.py 1970-01-01 00:00:00 +0000
3+++ tests/autopilot/ubuntuuitoolkit/tests/components/test_units.py 2015-04-13 18:20:25 +0000
4@@ -0,0 +1,61 @@
5+# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
6+#
7+# Copyright (C) 2015 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+"""Tests for the Ubuntu UI Toolkit units helpers."""
22+
23+import logging
24+import os
25+import testscenarios
26+import testtools
27+
28+import fixtures
29+
30+from ubuntuuitoolkit import (
31+ fixture_setup,
32+ units
33+)
34+
35+
36+logger = logging.getLogger(__name__)
37+
38+
39+class UnitsTestCase(testscenarios.TestWithScenarios,
40+ testtools.TestCase):
41+
42+ WIDTH_IN_GU = 20
43+
44+ path = os.path.abspath(__file__)
45+ dir_path = os.path.dirname(path)
46+ test_qml_file_path = os.path.join(
47+ dir_path, 'test_units.UnitsTestCase.qml')
48+
49+ scenarios = [
50+ ('with default GRID_UNIT_PX', {'grid_unit_px': '',
51+ 'expected_pixels': 160}),
52+ ('with GRID_UNIT_PX environment variable set', {'grid_unit_px': '10',
53+ 'expected_pixels': 200})
54+ ]
55+
56+ def setUp(self):
57+ self.useFixture(fixtures.EnvironmentVariable(
58+ 'GRID_UNIT_PX', self.grid_unit_px))
59+ self.useFixture(fixture_setup.InitctlEnvironmentVariable(
60+ global_=True, GRID_UNIT_PX=self.grid_unit_px))
61+ super(UnitsTestCase, self).setUp()
62+
63+ def test_gu(self):
64+ pixels = units.gu(self.WIDTH_IN_GU)
65+ self.assertEquals(pixels, self.expected_pixels)
66
67=== added file 'tests/autopilot/ubuntuuitoolkit/units.py'
68--- tests/autopilot/ubuntuuitoolkit/units.py 1970-01-01 00:00:00 +0000
69+++ tests/autopilot/ubuntuuitoolkit/units.py 2015-04-13 18:20:25 +0000
70@@ -0,0 +1,38 @@
71+# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
72+#
73+# Copyright (C) 2015 Canonical Ltd.
74+#
75+# This program is free software; you can redistribute it and/or modify
76+# it under the terms of the GNU Lesser General Public License as published by
77+# the Free Software Foundation; version 3.
78+#
79+# This program is distributed in the hope that it will be useful,
80+# but WITHOUT ANY WARRANTY; without even the implied warranty of
81+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
82+# GNU Lesser General Public License for more details.
83+#
84+# You should have received a copy of the GNU Lesser General Public License
85+# along with this program. If not, see <http://www.gnu.org/licenses/>.
86+
87+"""Ubuntu UI Toolkit units helpers."""
88+
89+import os
90+
91+from ubuntuuitoolkit import environment
92+
93+
94+ENV_GRID_UNIT_PX = 'GRID_UNIT_PX'
95+DEFAULT_GRID_UNIT_PX = 8
96+
97+
98+def get_grid_unit():
99+ grid_unit_px = os.environ.get(ENV_GRID_UNIT_PX, None)
100+ if not grid_unit_px and environment.is_initctl_env_var_set(
101+ ENV_GRID_UNIT_PX):
102+ grid_unit_px = environment.get_initctl_env_var(ENV_GRID_UNIT_PX)
103+ return float(grid_unit_px or DEFAULT_GRID_UNIT_PX)
104+
105+
106+def gu(value):
107+ """"Return the number of pixels corresponding to value in grid units."""
108+ return value * get_grid_unit()

Subscribers

People subscribed via source and target branches