Beispiel #1
0
    def test__1(self):
        ''' Make sure that depth_visit() works OK w/ empty components '''

        visit_called = [0]
        def on_visit_called(*args):
            ''' Just an helper function '''
            visit_called[0] += 1

        utils_path.depth_visit('/foo', [], on_visit_called)

        self.assertFalse(visit_called[0])
Beispiel #2
0
    def test__7(self):
        ''' Make sure that depth_visit() correctly flags the leaf node '''

        # The result depends on the OS
        expected = os.sep.join(['', 'foo', 'bar', 'baz',
                                'barbar', 'bazbaz'])

        failure = [False]
        def on_visit_called(*args):
            ''' Just an helper function '''
            if args[1] and args[0] != expected:
                failure[0] = True

        components = ['bar', 'baz', 'barbar', 'bazbaz']
        utils_path.depth_visit('/foo', components, on_visit_called)
        self.assertFalse(failure[0])
Beispiel #3
0
    def test__6(self):
        ''' Make sure that depth_visit() visits in the expected order '''

        # The result depends on the OS
        expected = [
                    os.sep.join(['', 'foo', 'bar']),
                    os.sep.join(['', 'foo', 'bar', 'baz']),
                    os.sep.join(['', 'foo', 'bar', 'baz', 'barbar',]),
                    os.sep.join(['', 'foo', 'bar', 'baz', 'barbar', 'bazbaz']),
                   ]

        visit_order = []
        def on_visit_called(*args):
            ''' Just an helper function '''
            visit_order.append(args[0])

        components = ['bar', 'baz', 'barbar', 'bazbaz']
        utils_path.depth_visit('/foo', components, on_visit_called)
        self.assertEquals(visit_order, expected)
Beispiel #4
0
    def test__2(self):
        ''' Make sure that depth_visit() accepts a non-ascii prefix '''

        visit = {
            "count": 0,
            "expect_path": [
                six.b("/foo\xc3\xa8").decode("utf-8") + "/bar",
                six.b("/foo\xc3\xa8").decode("utf-8") + "/bar" + "/baz",
            ],
            "expect_leaf": [
                False,
                True
            ],
        }

        def on_visit_called(path, leaf):
            ''' Just an helper function '''
            self.assertEqual(path, visit["expect_path"][visit["count"]])
            self.assertEqual(leaf, visit["expect_leaf"][visit["count"]])
            visit["count"] += 1

        utils_path.depth_visit(six.b('/foo\xc3\xa8'), ['bar',
          'baz'], on_visit_called)
 def datadir_touch(self, components):
     ''' Touch a file below datadir '''
     return utils_path.depth_visit(self.datadir, components, self._visit)