Mercurial > mozilla > hg > ProfileManager
annotate profilemanager/tests/test.py @ 65:1cd3e3c71bff
determine which backup to use from the given date
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Fri, 07 May 2010 14:14:17 -0700 |
parents | dc9324b52c2a |
children | 6cb674db8f51 |
rev | line source |
---|---|
12 | 1 #!/usr/bin/env python |
2 | |
32
6f2ad307fdda
dont use any testing framework because they make testing hard
Jeff Hammel <jhammel@mozilla.com>
parents:
28
diff
changeset
|
3 import os |
6f2ad307fdda
dont use any testing framework because they make testing hard
Jeff Hammel <jhammel@mozilla.com>
parents:
28
diff
changeset
|
4 from profilemanager import ProfileManager |
12 | 5 |
32
6f2ad307fdda
dont use any testing framework because they make testing hard
Jeff Hammel <jhammel@mozilla.com>
parents:
28
diff
changeset
|
6 # Get the path to the test profiles.ini file: |
6f2ad307fdda
dont use any testing framework because they make testing hard
Jeff Hammel <jhammel@mozilla.com>
parents:
28
diff
changeset
|
7 from pkg_resources import resource_filename |
6f2ad307fdda
dont use any testing framework because they make testing hard
Jeff Hammel <jhammel@mozilla.com>
parents:
28
diff
changeset
|
8 profiles_dir = os.path.join('tests', 'profiles') |
6f2ad307fdda
dont use any testing framework because they make testing hard
Jeff Hammel <jhammel@mozilla.com>
parents:
28
diff
changeset
|
9 path = os.path.join(profiles_dir, 'profiles.ini') |
6f2ad307fdda
dont use any testing framework because they make testing hard
Jeff Hammel <jhammel@mozilla.com>
parents:
28
diff
changeset
|
10 profiles = resource_filename('profilemanager', path) |
6f2ad307fdda
dont use any testing framework because they make testing hard
Jeff Hammel <jhammel@mozilla.com>
parents:
28
diff
changeset
|
11 profiles_dir = resource_filename('profilemanager', profiles_dir) |
34 | 12 assert os.path.exists(profiles), '%s does not exist' % profiles |
13 assert os.path.exists(profiles_dir), '%s does not exist' % profiles_dir | |
12 | 14 |
32
6f2ad307fdda
dont use any testing framework because they make testing hard
Jeff Hammel <jhammel@mozilla.com>
parents:
28
diff
changeset
|
15 # Instatiate a ProfileManager: |
6f2ad307fdda
dont use any testing framework because they make testing hard
Jeff Hammel <jhammel@mozilla.com>
parents:
28
diff
changeset
|
16 manager = ProfileManager(profiles) |
12 | 17 |
32
6f2ad307fdda
dont use any testing framework because they make testing hard
Jeff Hammel <jhammel@mozilla.com>
parents:
28
diff
changeset
|
18 # Remove any profiles that didn't get cleaned up: |
6f2ad307fdda
dont use any testing framework because they make testing hard
Jeff Hammel <jhammel@mozilla.com>
parents:
28
diff
changeset
|
19 profiles_dict = manager.profiles_dict() |
6f2ad307fdda
dont use any testing framework because they make testing hard
Jeff Hammel <jhammel@mozilla.com>
parents:
28
diff
changeset
|
20 for profile in profiles_dict: |
6f2ad307fdda
dont use any testing framework because they make testing hard
Jeff Hammel <jhammel@mozilla.com>
parents:
28
diff
changeset
|
21 manager.remove(profile) |
34 | 22 assert os.listdir(profiles_dir) == ['profiles.ini'], 'profiles_dir isnt empty except profiles.ini' |
23 assert file(profiles).read().strip() == '[General]', 'profiles.ini isnt nearly empty' | |
32
6f2ad307fdda
dont use any testing framework because they make testing hard
Jeff Hammel <jhammel@mozilla.com>
parents:
28
diff
changeset
|
24 |
6f2ad307fdda
dont use any testing framework because they make testing hard
Jeff Hammel <jhammel@mozilla.com>
parents:
28
diff
changeset
|
25 # Create a new profile: |
6f2ad307fdda
dont use any testing framework because they make testing hard
Jeff Hammel <jhammel@mozilla.com>
parents:
28
diff
changeset
|
26 profiledir = manager.new('testprofile') |
35 | 27 assert profiledir.endswith('.testprofile'), 'profiledir should end with testprofile, instead it is %s' % profiledir |
39 | 28 assert manager.list() == ['testprofile'] |
12 | 29 |
43 | 30 # Clone the profile: |
31 manager.clone('testprofile', 'cloneprofile') | |
32 assert sorted(manager.list()) == ['cloneprofile', 'testprofile'] | |
44 | 33 manager.remove('cloneprofile') |
43 | 34 |
50 | 35 # Backup the profile |
36 manager.backup('testprofile') | |
51
dc9324b52c2a
* add write convenience function
Jeff Hammel <jhammel@mozilla.com>
parents:
50
diff
changeset
|
37 # TODO: manager.restore('testprofile') |
50 | 38 |
32
6f2ad307fdda
dont use any testing framework because they make testing hard
Jeff Hammel <jhammel@mozilla.com>
parents:
28
diff
changeset
|
39 # Cleanup: |
6f2ad307fdda
dont use any testing framework because they make testing hard
Jeff Hammel <jhammel@mozilla.com>
parents:
28
diff
changeset
|
40 manager.remove('testprofile') |
39 | 41 assert manager.list() == [] |
49
cbd471e0146f
the variable profiles, not the string
Jeff Hammel <jhammel@mozilla.com>
parents:
48
diff
changeset
|
42 f = file(profiles, 'w') |
48
09a2666999fa
* restore profiles.ini to base in tests
Jeff Hammel <jhammel@mozilla.com>
parents:
44
diff
changeset
|
43 print >> f, '[General]' |