~yamahata/nova/volume-clone

« back to all changes in this revision

Viewing changes to nova/tests/test_misc.py

  • Committer: Tarmac
  • Author(s): Jason Kölker
  • Date: 2011-05-02 19:07:02 UTC
  • mfrom: (1003.4.1 lp765159)
  • Revision ID: tarmac-20110502190702-cvxlmumvabf5tgn6
add support for git checking and a default of failing if the history can't be read

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
class ProjectTestCase(test.TestCase):
30
30
    def test_authors_up_to_date(self):
31
31
        topdir = os.path.normpath(os.path.dirname(__file__) + '/../../')
 
32
        missing = set()
 
33
        contributors = set()
 
34
        mailmap = parse_mailmap(os.path.join(topdir, '.mailmap'))
 
35
        authors_file = open(os.path.join(topdir, 'Authors'), 'r').read()
 
36
 
32
37
        if os.path.exists(os.path.join(topdir, '.bzr')):
33
 
            contributors = set()
34
 
 
35
 
            mailmap = parse_mailmap(os.path.join(topdir, '.mailmap'))
36
 
 
37
38
            import bzrlib.workingtree
38
39
            tree = bzrlib.workingtree.WorkingTree.open(topdir)
39
40
            tree.lock_read()
47
48
                    for r in revs:
48
49
                        for author in r.get_apparent_authors():
49
50
                            email = author.split(' ')[-1]
50
 
                            contributors.add(str_dict_replace(email, mailmap))
51
 
 
52
 
                authors_file = open(os.path.join(topdir, 'Authors'),
53
 
                                    'r').read()
54
 
 
55
 
                missing = set()
56
 
                for contributor in contributors:
57
 
                    if contributor == 'nova-core':
58
 
                        continue
59
 
                    if not contributor in authors_file:
60
 
                        missing.add(contributor)
61
 
 
62
 
                self.assertTrue(len(missing) == 0,
63
 
                                '%r not listed in Authors' % missing)
 
51
                            contributors.add(str_dict_replace(email,
 
52
                                                              mailmap))
64
53
            finally:
65
54
                tree.unlock()
66
55
 
 
56
        elif os.path.exists(os.path.join(topdir, '.git')):
 
57
            import git
 
58
            repo = git.Repo(topdir)
 
59
            for commit in repo.head.commit.iter_parents():
 
60
                email = commit.author.email
 
61
                if email is None:
 
62
                    email = commit.author.name
 
63
                if 'nova-core' in email:
 
64
                    continue
 
65
                if email.split(' ')[-1] == '<>':
 
66
                    email = email.split(' ')[-2]
 
67
                email = '<' + email + '>'
 
68
                contributors.add(str_dict_replace(email, mailmap))
 
69
 
 
70
        else:
 
71
            self.assertTrue(False, 'Cannot read commit history')
 
72
 
 
73
        for contributor in contributors:
 
74
            if contributor == 'nova-core':
 
75
                continue
 
76
            if not contributor in authors_file:
 
77
                missing.add(contributor)
 
78
 
 
79
        self.assertTrue(len(missing) == 0,
 
80
                        '%r not listed in Authors' % missing)
 
81
 
67
82
 
68
83
class LockTestCase(test.TestCase):
69
84
    def test_synchronized_wrapped_function_metadata(self):