Merge lp:~om26er/camera-app/test-fix into lp:camera-app

Proposed by Omer Akram
Status: Merged
Approved by: Florian Boucault
Approved revision: 551
Merged at revision: 556
Proposed branch: lp:~om26er/camera-app/test-fix
Merge into: lp:camera-app
Diff against target: 28 lines (+10/-9)
1 file modified
tests/autopilot/camera_app/tests/__init__.py (+10/-9)
To merge this branch: bzr merge lp:~om26er/camera-app/test-fix
Reviewer Review Type Date Requested Status
PS Jenkins bot continuous-integration Needs Fixing
Leo Arias (community) Approve
Ubuntu Phablet Team Pending
Review via email: mp+256382@code.launchpad.net

Commit message

Autopilot: Ensure the media directories exist before trying to delete data from them.

Description of the change

Autopilot: Ensure the media directories exist before trying to delete data from them.

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

Thanks Omer.
You can extract a method for the common bits of both cases.

review: Needs Fixing
lp:~om26er/camera-app/test-fix updated
550. By Omer Akram

reuse code

Revision history for this message
Omer Akram (om26er) wrote :

> Thanks Omer.
> You can extract a method for the common bits of both cases.

Done. I am not able to decide though on what should be the name of the method which checks if a directory exists or not.

I named is directory_exists() would is_directory_there() better or does_directory_exist() ? Or anything else.

lp:~om26er/camera-app/test-fix updated
551. By Omer Akram

no need to write a method to check if a directory exists, rather make direct call to os.path.exists

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

thank you.

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'tests/autopilot/camera_app/tests/__init__.py'
2--- tests/autopilot/camera_app/tests/__init__.py 2015-03-10 13:52:56 +0000
3+++ tests/autopilot/camera_app/tests/__init__.py 2015-04-30 17:17:06 +0000
4@@ -90,15 +90,16 @@
5 return MainWindow(self.app)
6
7 def delete_all_media(self):
8- picture_files = os.listdir(self.pictures_dir)
9- for f in picture_files:
10- f = os.path.join(self.pictures_dir, f)
11- if os.path.isfile(f):
12- os.remove(f)
13-
14- video_files = os.listdir(self.videos_dir)
15- for f in video_files:
16- f = os.path.join(self.videos_dir, f)
17+ if os.path.exists(self.pictures_dir):
18+ delete_all_files_in_directory(self.pictures_dir)
19+
20+ if os.path.exists(self.videos_dir):
21+ delete_all_files_in_directory(self.videos_dir)
22+
23+ def delete_all_files_in_directory(self, directory):
24+ files = os.listdir(directory)
25+ for f in files:
26+ f = os.path.join(directory, f)
27 if os.path.isfile(f):
28 os.remove(f)
29

Subscribers

People subscribed via source and target branches