Merge lp:~om26er/ubuntu-weather-app/db_stab2 into lp:ubuntu-weather-app/obsolete.trunk

Proposed by Omer Akram on 2013-12-17
Status: Superseded
Proposed branch: lp:~om26er/ubuntu-weather-app/db_stab2
Merge into: lp:ubuntu-weather-app/obsolete.trunk
Diff against target: 62 lines (+22/-4)
3 files modified
tests/autopilot/ubuntu_weather_app/Databases/34e1e542f2f083ff18f537b07a380071.ini (+6/-0)
tests/autopilot/ubuntu_weather_app/tests/__init__.py (+15/-0)
tests/autopilot/ubuntu_weather_app/tests/test_mainview.py (+1/-4)
To merge this branch: bzr merge lp:~om26er/ubuntu-weather-app/db_stab2
Reviewer Review Type Date Requested Status
Ubuntu Phone Apps Jenkins Bot continuous-integration Needs Fixing on 2013-12-17
Sergio Schvezov (community) Needs Fixing on 2013-12-17
Ubuntu Weather Developers 2013-12-17 Pending
Review via email: mp+199321@code.launchpad.net

This proposal has been superseded by a proposal from 2013-12-17.

Commit message

use an archived db for mainview tests

To post a comment you must log in.
Sergio Schvezov (sergiusens) wrote :

for readability I would prefer path.join to be used here
34 + db_path = os.path.expanduser(db_dir + db_file)

Sergio Schvezov (sergiusens) wrote :

37 + subprocess.check_call([
38 + "mkdir",
39 + "-p",
40 + "~/.local/share/com.ubuntu.weather/"])

why aren't you usig os.makedirs?

review: Needs Fixing
170. By Omer Akram on 2013-12-17

database with a big D

Sergio Schvezov (sergiusens) wrote :

32 + db_dir = "~/.local/share/com.ubuntu.weather/Databases/"
33 + db_file = "34e1e542f2f083ff18f537b07a380071.sqlite"
34 + db_path = os.path.expanduser(db_dir + db_file)
35 +
36 + if not os.path.exists(db_path):
37 + subprocess.check_call([
38 + "mkdir",
39 + "-p",
        You need the module path
40 + "~/.local/share/com.ubuntu.weather/"])
41 + shutil.copytree("ubuntu_weather_app/databases/", db_dir)

Approximation...
db_dir = "~/.local/share/com.ubuntu.weather/Databases/"
db_file = "34e1e542f2f083ff18f537b07a380071.sqlite"
db_path = os.path.join(os.path.expanduser(db_dir, db_file))
if not os.path.exists(db_path):
    # it's what we want
    os.makedirs(db_dir)
    # you'll need the python module location
    shutil.copytree("ubuntu_weather_app/Databases/", db_dir)

review: Needs Fixing
171. By Omer Akram on 2013-12-17

fix per suggests

Nicholas Skaggs (nskaggs) wrote :

Any concerns about the relative copy?

shutil.copytree("ubuntu_weather_app/Databases/", db_dir)

Nicholas Skaggs (nskaggs) wrote :

Runs on my mako with and without existing db

Sergio Schvezov (sergiusens) wrote :

Personally I would of done something closer to (only one hardcoded path)

=== modified file 'tests/autopilot/ubuntu_weather_app/tests/__init__.py'
--- tests/autopilot/ubuntu_weather_app/tests/__init__.py 2013-12-17 17:09:10 +0000
+++ tests/autopilot/ubuntu_weather_app/tests/__init__.py 2013-12-17 17:25:10 +0000
@@ -89,13 +89,14 @@
         return self.app.select_single("QQuickView")

     def ensure_db(self):
- db_dir = "~/.local/share/com.ubuntu.weather/Databases/"
+ weather_dir = os.path.expanduser(
+ "~/.local/share/com.ubuntu.weather")
+ db_dir = os.path.join(weather_dir, 'Databases')
         db_file = "34e1e542f2f083ff18f537b07a380071.sqlite"
- abs_path = os.path.expanduser(db_dir)
- db_path = os.path.join(abs_path, db_file)
+ db_path = os.path.join(db_dir, db_file)

         if not os.path.exists(db_path):
- os.makedirs(os.path.expanduser("~/.local/share/com.ubuntu.weather"))
+ os.makedirs(weather_dir)
             shutil.copytree("ubuntu_weather_app/Databases/", db_dir)
             self.assertThat(
                 lambda: os.path.exists(db_path),

Sergio Schvezov (sergiusens) wrote :

And for the module path you'll need something like

        database_tmpl_dir = os.path.join(os.path.dirname(ubuntu_weather_app.__file__),
                                   'Databases')

Nicholas Skaggs (nskaggs) wrote :

I agree with Sergio. Should be more robust that way. Thanks Sergio!

Nicholas Skaggs (nskaggs) wrote :

I would also add a logger line saying you are creating the database when you do it :-)

172. By Omer Akram on 2013-12-17

fix this fraking thing

173. By Omer Akram on 2013-12-17

fix per sergio' suggestions

Omer Akram (om26er) wrote :

Not creating the dir in the test code. shutil.copytree calls makedirs so no need.

Unmerged revisions

173. By Omer Akram on 2013-12-17

fix per sergio' suggestions

172. By Omer Akram on 2013-12-17

fix this fraking thing

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added directory 'tests/autopilot/ubuntu_weather_app/Databases'
2=== added file 'tests/autopilot/ubuntu_weather_app/Databases/34e1e542f2f083ff18f537b07a380071.ini'
3--- tests/autopilot/ubuntu_weather_app/Databases/34e1e542f2f083ff18f537b07a380071.ini 1970-01-01 00:00:00 +0000
4+++ tests/autopilot/ubuntu_weather_app/Databases/34e1e542f2f083ff18f537b07a380071.ini 2013-12-17 17:48:43 +0000
5@@ -0,0 +1,6 @@
6+[General]
7+Description=Default Ubuntu weather app
8+Driver=QSQLITE
9+EstimatedSize=100000
10+Name=com.ubuntu.weather
11+Version=0.3
12
13=== added file 'tests/autopilot/ubuntu_weather_app/Databases/34e1e542f2f083ff18f537b07a380071.sqlite'
14Binary files tests/autopilot/ubuntu_weather_app/Databases/34e1e542f2f083ff18f537b07a380071.sqlite 1970-01-01 00:00:00 +0000 and tests/autopilot/ubuntu_weather_app/Databases/34e1e542f2f083ff18f537b07a380071.sqlite 2013-12-17 17:48:43 +0000 differ
15=== modified file 'tests/autopilot/ubuntu_weather_app/tests/__init__.py'
16--- tests/autopilot/ubuntu_weather_app/tests/__init__.py 2013-12-13 15:30:46 +0000
17+++ tests/autopilot/ubuntu_weather_app/tests/__init__.py 2013-12-17 17:48:43 +0000
18@@ -14,6 +14,7 @@
19 import sqlite3
20 import time
21 import logging
22+import shutil
23
24 from autopilot.input import Mouse, Touch, Pointer
25 from autopilot.platform import model
26@@ -86,6 +87,20 @@
27 def get_qml_view(self):
28 return self.app.select_single("QQuickView")
29
30+ def ensure_db(self):
31+ logger.debug("moving the test database")
32+ weather_dir = os.path.expanduser(
33+ "~/.local/share/com.ubuntu.weather")
34+ db_dir = os.path.join(weather_dir, 'Databases')
35+ db_file = "34e1e542f2f083ff18f537b07a380071.sqlite"
36+ db_path = os.path.join(db_dir, db_file)
37+
38+ if not os.path.exists(db_path):
39+ shutil.copytree("ubuntu_weather_app/Databases", db_dir)
40+ self.assertThat(
41+ lambda: os.path.exists(db_path),
42+ Eventually(Equals(True)))
43+
44 @property
45 def main_window(self):
46 return self.app.select_single(MainView)
47
48=== modified file 'tests/autopilot/ubuntu_weather_app/tests/test_mainview.py'
49--- tests/autopilot/ubuntu_weather_app/tests/test_mainview.py 2013-12-11 20:24:42 +0000
50+++ tests/autopilot/ubuntu_weather_app/tests/test_mainview.py 2013-12-17 17:48:43 +0000
51@@ -27,10 +27,7 @@
52 """ This is needed to wait for the application to start.
53 In the testfarm, the application may take some time to show up."""
54 def setUp(self):
55- #close app
56- #logger.debug("Closing app")
57- #self.doCleanups()
58- #wipe the existing database and create a new blank one
59+ self.ensure_db()
60 self.create_blank_db()
61 # add settings to storage
62 logger.debug("Adding fake data to new database")

Subscribers

People subscribed via source and target branches