示例#1
0
 def test_getChildFiles_dir(self):
     """
     Given a directory, return all children files.
     """
     root = FilePath(self.mktemp())
     dir1 = root.child('dir1')
     dir2 = dir1.child('dir2')
     dir2.makedirs()
     
     f1 = root.child('f1')
     f2 = dir1.child('f2')
     f3 = dir2.child('f3')
     
     f1.setContent('foo')
     f2.setContent('foo')
     f3.setContent('foo')
     
     b = FileBuilder()
     
     r = b._getChildFiles(root)
     self.assertEqual(set(r), set([f1, f2, f3]),
         "Should find all files that are descendants")
     
     r = b._getChildFiles(dir1)
     self.assertEqual(set(r), set([f2, f3]))
示例#2
0
 def test_findHeads_testPath(self):
     """
     Find heads should find all the heads that match the given testPath
     """
     root = FilePath(self.mktemp())
     
     foo = root.child('foo')
     foo.makedirs()
     test1 = foo.child('test1')
     test2 = foo.child('test2')
     bar = foo.child('bar')
     baz = bar.child('baz')
     
     test1.setContent('test1')
     test2.setContent('test2')
     bar.makedirs()
     baz.setContent('baz')
     
     b = FileBuilder(root)
     
     r = list(b._findHeads('foo', '*'))
     self.assertEqual(len(r), 3, "Should find all the heads with *")
     self.assertEqual(set(r), set([test1, test2, bar]))
     
     r = list(b._findHeads('foo', 'test*'))
     self.assertEqual(len(r), 2)
     self.assertEqual(set(r), set([test1, test2]))
     
     # subdirectory
     r = list(b._findHeads('foo', 'bar/baz'))
     self.assertEqual(r, [baz])
示例#3
0
 def test_getChildFiles_file(self):
     """
     Given a file, return the file
     """
     root = FilePath(self.mktemp())
     root.setContent('something')
     b = FileBuilder()
     r = list(b._getChildFiles(root))
     self.assertEqual(r, [root])
示例#4
0
 def test__build(self):
     """
     _build should
         - get the results of findBuilds,
         - set the version attribute of each Build,
         - call run() on each Build,
         - pass each Build.toDict through emit
         - wait on the Build's completion to send the finished build.toDict
           through emit.
     """
     b = FileBuilder('foo')
     
     r = [Build()]
     
     # fake out Build.run()
     run_called = []
     def fakerun():
         run_called.append(True)
     r[0].run = fakerun
     
     # fake out findBuilds()
     b.findBuilds = lambda *ign: r
     
     # fake out emit()
     emit_called = []
     b.emit = emit_called.append
     
     
     b._build(dict(version='version', project='foo', test_path='bar'))
     
     
     # version should be set on the Build
     self.assertEqual(r[0].version, 'version',
         "Should have set the version on the Build")
     
     self.assertEqual(run_called, [True],
         "Build.run() should have been called")
     
     self.assertEqual(emit_called, [r[0].toDict()],
         "Builder.emit() should have been called")
     
     # reset the fake
     emit_called.pop()
     
     # finish the build manually.
     r[0].done.callback(r[0])
     
     self.assertEqual(emit_called, [r[0].toDict()],
         "When the build finishes, Builder.emit should be called")
示例#5
0
    def test_findBuilds(self):
        """
        It should call a few functions, passing their results around,
        ending up with FileBuild instances with the correct properties set.
        """
        root = FilePath(self.mktemp())
        # project/
        project = root.child('project')
        project.makedirs()
        
        # project/foo
        foo = project.child('foo')
        # project/bar
        bar = project.child('bar')
        foo.setContent('foo')
        bar.setContent('bar')
        
        b = FileBuilder(root)
        
        class Spy:
            
            def __init__(self, func):
                self.func = func
                self.called = []
            
            def __call__(self, *args):
                self.called.append(args)
                return self.func(*args)


        b._findHeads = Spy(b._findHeads)
        b._getChildFiles = Spy(b._getChildFiles)
        
        r = list(b.findBuilds('project', '*'))
        
        self.assertTrue(b._findHeads.called)
        self.assertTrue(('project', '*') in b._findHeads.called)
        
        self.assertEqual(len(b._getChildFiles.called), 2)
        
        expected = set([
            ('project', 'foo', b, foo),
            ('project', 'bar', b, bar),
        ])
        
        actual = [(x.project, x.test_path, x.builder, x._filepath) for x in r]
        
        self.assertEqual(expected, set(actual))        
        self.assertEqual(len(r), 2)
示例#6
0
 def test_findHeads_project(self):
     """
     Find heads with only a project given should find a single FilePath
     if it exists
     """
     root = FilePath(self.mktemp())
     root.makedirs()
     b = FileBuilder(root)
     
     # dne
     r = list(b._findHeads('foo'))
     self.assertEqual(r, [], "Should not find paths that don't exist")
     
     # exists
     root.child('foo').setContent('gobbledegook')
     r = list(b._findHeads('foo'))
     self.assertEqual(r, [root.child('foo')])