annotate profilemanager/tests/test.py @ 69:86b137d49467

use only the path element, not the whole tuple
author Jeff Hammel <jhammel@mozilla.com>
date Fri, 07 May 2010 15:57:14 -0700
parents 6cb674db8f51
children 619f5918b998
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
12
a07e53273b70 adding stubs for tests
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
1 #!/usr/bin/env python
a07e53273b70 adding stubs for tests
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
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
a07e53273b70 adding stubs for tests
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
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
5a27ad649768 more verbose asserts
Jeff Hammel <jhammel@mozilla.com>
parents: 32
diff changeset
12 assert os.path.exists(profiles), '%s does not exist' % profiles
5a27ad649768 more verbose asserts
Jeff Hammel <jhammel@mozilla.com>
parents: 32
diff changeset
13 assert os.path.exists(profiles_dir), '%s does not exist' % profiles_dir
12
a07e53273b70 adding stubs for tests
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
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
a07e53273b70 adding stubs for tests
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
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
5a27ad649768 more verbose asserts
Jeff Hammel <jhammel@mozilla.com>
parents: 32
diff changeset
22 assert os.listdir(profiles_dir) == ['profiles.ini'], 'profiles_dir isnt empty except profiles.ini'
5a27ad649768 more verbose asserts
Jeff Hammel <jhammel@mozilla.com>
parents: 32
diff changeset
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
b9d7f5f61e23 correct syntax error
Jeff Hammel <jhammel@mozilla.com>
parents: 34
diff changeset
27 assert profiledir.endswith('.testprofile'), 'profiledir should end with testprofile, instead it is %s' % profiledir
39
30fc269a15c8 * add additional tests
Jeff Hammel <jhammel@mozilla.com>
parents: 35
diff changeset
28 assert manager.list() == ['testprofile']
12
a07e53273b70 adding stubs for tests
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
29
43
49cc40572f46 test cloning
Jeff Hammel <jhammel@mozilla.com>
parents: 39
diff changeset
30 # Clone the profile:
49cc40572f46 test cloning
Jeff Hammel <jhammel@mozilla.com>
parents: 39
diff changeset
31 manager.clone('testprofile', 'cloneprofile')
49cc40572f46 test cloning
Jeff Hammel <jhammel@mozilla.com>
parents: 39
diff changeset
32 assert sorted(manager.list()) == ['cloneprofile', 'testprofile']
44
8eb997fd6e79 remove the test clone
Jeff Hammel <jhammel@mozilla.com>
parents: 43
diff changeset
33 manager.remove('cloneprofile')
43
49cc40572f46 test cloning
Jeff Hammel <jhammel@mozilla.com>
parents: 39
diff changeset
34
50
4cd6fc940407 * test backup
Jeff Hammel <jhammel@mozilla.com>
parents: 49
diff changeset
35 # Backup the profile
4cd6fc940407 * test backup
Jeff Hammel <jhammel@mozilla.com>
parents: 49
diff changeset
36 manager.backup('testprofile')
68
6cb674db8f51 more backup+restore testing
Jeff Hammel <jhammel@mozilla.com>
parents: 51
diff changeset
37 backups = manager.backups('testprofile')
6cb674db8f51 more backup+restore testing
Jeff Hammel <jhammel@mozilla.com>
parents: 51
diff changeset
38 assert len(backups) == 1, "Expected one backup, instead got %d" % len(backups)
6cb674db8f51 more backup+restore testing
Jeff Hammel <jhammel@mozilla.com>
parents: 51
diff changeset
39 assert backups[0][0].startswith('testprofile')
6cb674db8f51 more backup+restore testing
Jeff Hammel <jhammel@mozilla.com>
parents: 51
diff changeset
40 manager.restore('testprofile')
6cb674db8f51 more backup+restore testing
Jeff Hammel <jhammel@mozilla.com>
parents: 51
diff changeset
41 manager.restore('testprofile', delete=True)
50
4cd6fc940407 * test backup
Jeff Hammel <jhammel@mozilla.com>
parents: 49
diff changeset
42
32
6f2ad307fdda dont use any testing framework because they make testing hard
Jeff Hammel <jhammel@mozilla.com>
parents: 28
diff changeset
43 # Cleanup:
6f2ad307fdda dont use any testing framework because they make testing hard
Jeff Hammel <jhammel@mozilla.com>
parents: 28
diff changeset
44 manager.remove('testprofile')
39
30fc269a15c8 * add additional tests
Jeff Hammel <jhammel@mozilla.com>
parents: 35
diff changeset
45 assert manager.list() == []
49
cbd471e0146f the variable profiles, not the string
Jeff Hammel <jhammel@mozilla.com>
parents: 48
diff changeset
46 f = file(profiles, 'w')
48
09a2666999fa * restore profiles.ini to base in tests
Jeff Hammel <jhammel@mozilla.com>
parents: 44
diff changeset
47 print >> f, '[General]'