~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to fai/arch/tests/test_revlib.py

  • Committer: Robert Collins
  • Date: 2005-09-13 15:11:39 UTC
  • mto: (147.2.6) (364.1.3 bzrtools)
  • mto: This revision was merged to the branch mainline in revision 324.
  • Revision ID: robertc@robertcollins.net-20050913151139-9ac920fc9d7bda31
TODOification

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
# arch-tag: eb042c78-5862-40b9-8570-bf7d62419dca
 
3
# Copyright (C) 2004 David Allouche <david@allouche.net>
 
4
#               2004 Canonical Ltd.
 
5
#
 
6
#    This program is free software; you can redistribute it and/or modify
 
7
#    it under the terms of the GNU General Public License as published by
 
8
#    the Free Software Foundation; either version 2 of the License, or
 
9
#    (at your option) any later version.
 
10
#
 
11
#    This program is distributed in the hope that it will be useful,
 
12
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
#    GNU General Public License for more details.
 
15
#
 
16
#    You should have received a copy of the GNU General Public License
 
17
#    along with this program; if not, write to the Free Software
 
18
#    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
19
 
 
20
"""Test cases for revision library handling
 
21
"""
 
22
 
 
23
import os
 
24
import arch
 
25
from arch.tests import framework
 
26
from arch.tests.framework import TestCase
 
27
 
 
28
 
 
29
class Empty(TestCase):
 
30
 
 
31
    tests = []
 
32
 
 
33
    def list_revlibs_empty(self):
 
34
        """iter_revision_libraries works when no revlib is registered"""
 
35
        self.assertEqual([], list(arch.iter_revision_libraries()))
 
36
    tests.append('list_revlibs_empty')
 
37
 
 
38
 
 
39
class Register(TestCase):
 
40
 
 
41
    tests = []
 
42
 
 
43
    def register_revision_library(self):
 
44
        """register_revision_library works"""
 
45
        revlib1_dir = self.arch_dir/'revlib1'
 
46
        os.mkdir(revlib1_dir)
 
47
        arch.register_revision_library(revlib1_dir)
 
48
        expected = [revlib1_dir]
 
49
        result = list(arch.iter_revision_libraries())
 
50
        self.assertEqual(expected, result)
 
51
        revlib2_dir = self.arch_dir/'revlib2'
 
52
        os.mkdir(revlib2_dir)
 
53
        arch.register_revision_library(revlib2_dir)
 
54
        expected = [revlib1_dir, revlib2_dir]
 
55
        expected.sort()
 
56
        result = list(arch.iter_revision_libraries())
 
57
        result.sort()
 
58
        self.assertEqual(expected, result)
 
59
    tests.append('register_revision_library')
 
60
 
 
61
    def register_revision_library_wants_abspath(self):
 
62
        """register_revision_library requires absolute path"""
 
63
        os.chdir(self.arch_dir)
 
64
        revlib_dir = 'revlib'
 
65
        os.mkdir(revlib_dir)
 
66
        def func(): arch.register_revision_library(revlib_dir)
 
67
        self.assertRaises(ValueError, func)
 
68
    tests.append('register_revision_library_wants_abspath')
 
69
 
 
70
 
 
71
class Unregister(TestCase):
 
72
 
 
73
    tests = []
 
74
 
 
75
    def unregister_revision_library(self):
 
76
        """unregister_revision_library works"""
 
77
        revlib1_dir = self.arch_dir/'revlib1'
 
78
        os.mkdir(revlib1_dir)
 
79
        arch.register_revision_library(revlib1_dir)
 
80
        revlib2_dir = self.arch_dir/'revlib2'
 
81
        os.mkdir(revlib2_dir)
 
82
        arch.register_revision_library(revlib2_dir)
 
83
        arch.unregister_revision_library(revlib1_dir)
 
84
        result = list(arch.iter_revision_libraries())
 
85
        self.assertEqual([revlib2_dir], result)
 
86
        arch.unregister_revision_library(revlib2_dir)
 
87
        result = list(arch.iter_revision_libraries())
 
88
        self.assertEqual([], result)
 
89
    tests.append('unregister_revision_library')
 
90
 
 
91
    def unregister_relative_revlib(self):
 
92
        """unregister_revision_library requires absolute path"""
 
93
        os.chdir(self.arch_dir)
 
94
        revlib_dir = self.arch_dir/'revlib'
 
95
        os.mkdir(revlib_dir)
 
96
        arch.register_revision_library(revlib_dir)
 
97
        def func():
 
98
            arch.unregister_revision_library(os.path.basename(revlib_dir))
 
99
        self.assertRaises(ValueError, func)
 
100
    tests.append('unregister_relative_revlib')
 
101
 
 
102
 
 
103
class List(TestCase):
 
104
 
 
105
    tests = []
 
106
 
 
107
    def extraSetup(self):
 
108
        self.set_my_id()
 
109
        self.create_archive()
 
110
        revlib1_dir = self.arch_dir/'revlib1'
 
111
        os.mkdir(revlib1_dir)
 
112
        arch.register_revision_library(revlib1_dir)
 
113
 
 
114
    def empty(self):
 
115
        self.assertEqual([], list(arch.iter_library_archives()))
 
116
    tests.append('empty')
 
117
 
 
118
    def one(self):
 
119
        self.create_version()
 
120
        self.create_working_tree(self.version)
 
121
        tree = self.working_tree
 
122
        tree.import_()
 
123
        tree.tree_revision.library_add()
 
124
        archive = tree.tree_version.archive
 
125
        self.assertEqual([archive], list(arch.iter_library_archives()))
 
126
        category = tree.tree_version.category
 
127
        self.assertEqual([category], list(archive.iter_library_categories()))
 
128
        branch = tree.tree_version.branch
 
129
        self.assertEqual([branch], list(category.iter_library_branches()))
 
130
        version = tree.tree_version
 
131
        self.assertEqual([version], list(branch.iter_library_versions()))
 
132
    tests.append('one')
 
133
 
 
134
 
 
135
def test_suite(limit=()):
 
136
    classes = (
 
137
        'Empty',
 
138
        'Register',
 
139
        'Unregister',
 
140
        'List',
 
141
        )
 
142
    return framework.make_test_suite(globals(), classes, limit)
 
143
 
 
144
def main(argv):
 
145
    return framework.run_test_suite(argv, test_suite)
 
146
 
 
147
if __name__ == "__main__":
 
148
    sys.exit(main(sys.argv))