~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to tests/upstream_import.py

  • Committer: Aaron Bentley
  • Date: 2006-12-13 02:50:41 UTC
  • Revision ID: aaron.bentley@utoronto.ca-20061213025041-sel3slhq12mqie1h
More test case unification

Show diffs side-by-side

added added

removed removed

Lines of Context:
54
54
        result.seek(0)
55
55
        return result
56
56
 
57
 
    def make_tar2(self):
 
57
    def make_archive2(self, builder):
58
58
        result = StringIO()
59
 
        tar_file = tarfile.open('project-0.2.tar', 'w', result)
 
59
        tar_file = builder(result)
60
60
        os.mkdir('project-0.2')
61
61
        tar_file.add('project-0.2')
62
62
        
69
69
        tar_file.add('project-0.2/README')
70
70
        tar_file.close()
71
71
 
72
 
        tar_file = tarfile.open('project-0.2.tar', 'a', result)
 
72
        tar_file = builder(result, 'a')
73
73
        tar_file.add('project-0.2/README')
74
74
 
75
75
        rmtree('project-0.2')
107
107
        self.assertIs(common_directory(['ab/c/d', 'ac/c/e']), None)
108
108
 
109
109
    def test_untar(self):
110
 
        tar_file = self.make_tar()
 
110
        def builder(fileobj, mode='w'):
 
111
            return tarfile.open('project-0.1.tar', mode, fileobj)
 
112
        self.archive_test(builder, import_tar)
 
113
 
 
114
    def test_unzip(self):
 
115
        def builder(fileobj, mode='w'):
 
116
            return ZipFileWrapper(fileobj, mode)
 
117
        self.archive_test(builder, import_zip)
 
118
 
 
119
    def archive_test(self, builder, importer):
 
120
        archive_file = self.make_archive(builder)
111
121
        tree = BzrDir.create_standalone_workingtree('tree')
112
 
        import_tar(tree, tar_file)
 
122
        importer(tree, archive_file)
113
123
        self.assertTrue(tree.path2id('README') is not None) 
114
124
        self.assertTrue(tree.path2id('FEEDME') is not None)
115
125
        self.assertTrue(os.path.isfile(tree.abspath('README')))
120
130
        f.write('I like food\n')
121
131
        f.close()
122
132
 
123
 
        tar_file = self.make_tar2()
124
 
        import_tar(tree, tar_file)
 
133
        archive_file = self.make_archive2(builder)
 
134
        importer(tree, archive_file)
125
135
        self.assertTrue(tree.path2id('README') is not None) 
126
136
        self.assertTrue(not os.path.exists(tree.abspath('FEEDME')))
127
137
 
138
148
        import_tar(tree, tar_file)
139
149
        self.assertTrue(tree.path2id('README') is not None) 
140
150
 
141
 
    def test_unzip(self):
142
 
        zip_file = self.make_zip()
143
 
        tree = BzrDir.create_standalone_workingtree('tree')
144
 
        import_zip(tree, zip_file)
145
 
        self.assertTrue(tree.path2id('README') is not None) 
146
 
        self.assertTrue(tree.path2id('FEEDME') is not None)
147
 
        self.assertTrue(os.path.isfile(tree.abspath('README')))
148
 
        self.assertEqual(tree.inventory[tree.path2id('README')].kind, 'file')
149
 
        self.assertEqual(tree.inventory[tree.path2id('FEEDME')].kind, 'file')
150
 
        
151
 
        f = file(tree.abspath('junk/food'), 'wb')
152
 
        f.write('I like food\n')
153
 
        f.close()
154
 
 
155
 
 
156
151
def test_suite():
157
152
    return makeSuite(TestImport)