Merge lp:~canonical-platform-qa/gallery-app/fix1376423-no_backup into lp:~canonical-platform-qa/gallery-app/clean_autopilot_setup

Proposed by Leo Arias
Status: Needs review
Proposed branch: lp:~canonical-platform-qa/gallery-app/fix1376423-no_backup
Merge into: lp:~canonical-platform-qa/gallery-app/clean_autopilot_setup
Prerequisite: lp:~canonical-platform-qa/gallery-app/fix1381259-launch_fixture
Diff against target: 108 lines (+21/-28)
1 file modified
tests/autopilot/gallery_app/tests/__init__.py (+21/-28)
To merge this branch: bzr merge lp:~canonical-platform-qa/gallery-app/fix1376423-no_backup
Reviewer Review Type Date Requested Status
PS Jenkins bot continuous-integration Pending
Ubuntu Phablet Team Pending
Review via email: mp+238383@code.launchpad.net

This proposal supersedes a proposal from 2014-10-14.

Commit message

Do not backup existing files during autopilot tests. We will assume a clean environment from now on.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote : Posted in a previous version of this proposal
review: Needs Fixing (continuous-integration)
Revision history for this message
Leo Arias (elopio) wrote : Posted in a previous version of this proposal

In order to remove the backups, we need to stop deleting the real folders.
In order to stop deleting the real folders, we need a better hierarchy of test cases and a fixture to launch the app.
I will start with the fixture.

1104. By Leo Arias

Fixed the method definition.

1105. By Leo Arias

Keep the database patching for now.

1106. By Leo Arias

Make the pictures dir location and configuration independent.

1107. By Leo Arias

Reverted to use the hardcoded path. The phone doesn't have xdg-user-dir.

1108. By Leo Arias

Raise an exception if the pictures directory is not empty.

1109. By Leo Arias

Clean the pictures directory.

1110. By Leo Arias

Clean the pictures directory.

Unmerged revisions

1110. By Leo Arias

Clean the pictures directory.

1109. By Leo Arias

Clean the pictures directory.

1108. By Leo Arias

Raise an exception if the pictures directory is not empty.

1107. By Leo Arias

Reverted to use the hardcoded path. The phone doesn't have xdg-user-dir.

1106. By Leo Arias

Make the pictures dir location and configuration independent.

1105. By Leo Arias

Keep the database patching for now.

1104. By Leo Arias

Fixed the method definition.

1103. By Leo Arias

Merged with prerequisite.

1102. By Leo Arias

Do not backup existing files during autopilot tests. We will assume a clean environment from now on.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'tests/autopilot/gallery_app/tests/__init__.py'
2--- tests/autopilot/gallery_app/tests/__init__.py 2014-10-20 19:50:32 +0000
3+++ tests/autopilot/gallery_app/tests/__init__.py 2014-10-20 19:50:32 +0000
4@@ -1,6 +1,6 @@
5 # -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
6 #
7-# Copyright (C) 2014 Canonical Ltd.
8+# Copyright (C) 2012, 2014 Canonical Ltd.
9 #
10 # This file is part of gallery-app.
11 #
12@@ -22,6 +22,7 @@
13 import logging
14 import shutil
15 import signal
16+from time import sleep
17
18 from testtools.matchers import Equals, NotEquals, GreaterThan
19 from autopilot.matchers import Eventually
20@@ -35,11 +36,13 @@
21 from gallery_app.emulators import main_screen
22 from gallery_app.emulators.gallery_utils import GalleryUtils
23
24-from time import sleep
25-
26 logger = logging.getLogger(__name__)
27
28
29+class GalleryException(Exception):
30+ pass
31+
32+
33 class GalleryTestCase(AutopilotTestCase):
34
35 """A common test case class that provides several useful methods for
36@@ -76,24 +79,13 @@
37 return fixture_setup.Launcher.installed_click
38
39 def _get_sample_destination_dir(self):
40- pic_dir = os.path.expanduser("~/Pictures")
41- pic_bak_dir = pic_dir + '.apbak'
42- # Only save and restore if it previously existed
43- if os.path.exists(pic_dir):
44- shutil.move(pic_dir, pic_bak_dir)
45- self.addCleanup(
46- logger.debug, "Restoring backed up pics to %s" % pic_dir)
47- self.addCleanup(shutil.move, pic_bak_dir, pic_dir)
48- return pic_dir
49+ return os.path.expanduser('~/Pictures')
50
51 def configure_db(self):
52 db = os.path.expanduser(self._db)
53- db_bak = db + '.apbak'
54- # Only save and restore if it previously existed
55 if os.path.exists(db):
56- shutil.move(db, db_bak)
57- self.addCleanup(shutil.move, db_bak, db)
58- if not os.path.exists(os.path.dirname(db)):
59+ os.remove(db)
60+ elif not os.path.exists(os.path.dirname(db)):
61 os.makedirs(os.path.dirname(db))
62 mock_db = os.path.join(self.sample_destination_dir, '.database',
63 'gallery_confined.sqlite')
64@@ -101,12 +93,9 @@
65
66 def configure_thumbnails(self):
67 thumbs = os.path.expanduser(self._thumbs)
68- thumbs_bak = thumbs + '.apbak'
69- # Only save and restore if it previously existed
70 if os.path.exists(thumbs):
71- shutil.move(thumbs, thumbs_bak)
72- self.addCleanup(shutil.move, thumbs_bak, thumbs)
73- if not os.path.exists(os.path.dirname(thumbs)):
74+ shutil.rmtree(thumbs)
75+ elif not os.path.exists(os.path.dirname(thumbs)):
76 os.makedirs(os.path.dirname(thumbs))
77 mock_thumbs = os.path.join(self.sample_destination_dir, '.thumbnails')
78 shutil.move(mock_thumbs, thumbs)
79@@ -114,9 +103,14 @@
80 def configure_sample_files(self, env_type):
81 self.sample_dir = resource_filename('gallery_app', 'data')
82 self.sample_destination_dir = self._get_sample_destination_dir()
83- if (os.path.exists(self.sample_destination_dir)):
84- shutil.rmtree(self.sample_destination_dir)
85- self.assertFalse(os.path.exists(self.sample_destination_dir))
86+ if os.path.exists(self.sample_destination_dir):
87+ try:
88+ os.rmdir(self.sample_destination_dir)
89+ except OSError:
90+ raise GalleryException('The pictures directory is not empty.')
91+
92+ self.addCleanup(shutil.rmtree, self.sample_destination_dir)
93+ self.addCleanup(os.mkdir, self.sample_destination_dir)
94
95 self.sample_file = os.path.join(
96 self.sample_destination_dir,
97@@ -132,9 +126,8 @@
98 self.sample_file_source = \
99 default_data_dir + self.sample_file_source
100
101- if env_type is fixture_setup.Launcher.installed_click:
102- self.configure_db()
103- self.configure_thumbnails()
104+ self.configure_db()
105+ self.configure_thumbnails()
106
107 def do_reset_config(self):
108 config = os.path.expanduser(

Subscribers

People subscribed via source and target branches

to all changes: