Beispiel #1
0
    def testDoubleDotRemoval(self):
        '''
        We have a directory with multiple empty 
        subdirectories whose name differs only for 
        different leading whitespaces:

         * base
           * ':2edir/file'
           * '.dir /file'

        Resulting tree must be:

         * base
           * .dir/file
           * .dir_/file
        '''

        for d in [':2edir', '.dir']:
            p = self.path.joinpath(d)
            p.mkdir()
            p.joinpath('file').touch()

        clean_dir(self.path, execute=True)

        self.assertEqual(4, len(list(self.path.glob('**/*'))), 'no')

        self.assertEqual(
            set(self.path.glob('**/*')),
            set([
                self.path.joinpath('.dir'),
                self.path.joinpath('.dir').joinpath('file'),
                self.path.joinpath('.dir_'),
                self.path.joinpath('.dir_').joinpath('file')
            ]), 'no')
Beispiel #2
0
    def testMultipleLeadingWhitespaceRemoval(self):
        '''
        We have a directory with multiple non-empty 
        subdirectories whose name differs only for 
        different leading whitespaces:

         * base
           * ' dir'
           * '  dir'
           * '   dir'

        Resulting tree must be:

         * base
           * dir
           * dir_
           * dir__ 
        '''

        for d in [' dir', '  dir', '   dir']:
            path = self.path.joinpath(d)
            path.mkdir()
            path.joinpath('file').touch()

        clean_dir(self.path, execute=True)

        self.assertEqual(3, len(list(self.path.iterdir())), 'no')

        self.assertEqual(
            set(x for x in self.path.iterdir()),
            set(self.path.joinpath(x) for x in ['dir', 'dir_', 'dir__']), 'no')
Beispiel #3
0
    def testDoubleDotRemovalOnEmptyDir(self):
        '''
        We have a directory with multiple empty 
        subdirectories whose name differs only for 
        different leading whitespaces:

         * base
           * 'd:2eir'
           * 'd:2eir '

        Resulting tree must be:

         * base
           * d.ir
        '''

        for d in ['d:2eir', 'd:2eir ']:
            self.path.joinpath(d).mkdir()

        clean_dir(self.path, execute=True)

        self.assertEqual(1, len(list(self.path.glob('**/*'))), 'no')

        self.assertEqual(set(self.path.glob('**/*')),
                         set([self.path.joinpath('d.ir')]), 'no')
Beispiel #4
0
    def testLeadingWhitespaceRemoval(self):

        self.path.joinpath(' dir').mkdir()

        clean_dir(self.path, execute=True)

        self.assertTrue(
            self.path.joinpath('dir').exists(),
            'leading space not removed: %s' % [x for x in self.path.iterdir()])
Beispiel #5
0
    def testDotRemoval(self):

        self.path.joinpath('di:2er').mkdir()

        clean_dir(self.path, execute=True)

        self.assertTrue(
            self.path.joinpath('di.r').exists(),
            'dot not removed: %s' % [x for x in self.path.iterdir()])
Beispiel #6
0
    def testSlashRemoval(self):

        self.path.joinpath('di:2fr').mkdir()

        clean_dir(self.path, execute=True)

        self.assertTrue(
            self.path.joinpath('di_r').exists(),
            'slash not removed: %s' % [x for x in self.path.iterdir()])
Beispiel #7
0
    def testIdempotency(self):
        a = set(x for x in self.populate(self.tempdir, depth=3, width=3))

        clean_dir(self.path, execute=True)
        b = set(x for x in self.path.glob('**/*'))

        clean_dir(self.path, execute=True)
        c = set(x for x in self.path.glob('**/*'))

        self.assertNotEqual(a, b, 'no')
        self.assertEqual(b, c, 'no')
Beispiel #8
0
    def testMainMethodDryRun(self):

        for d in [' dir', '  dir', '   dir']:
            path = self.path.joinpath(d)
            path.mkdir()
            path.joinpath(':2eDS_Store').touch()

        before = set(x for x in self.path.glob('**/*'))
        clean_dir(self.path, execute=False)
        after = set(x for x in self.path.glob('**/*'))

        self.assertEqual(before, after, 'no')
Beispiel #9
0
    def testRemover(self):

        self.path.joinpath(':2eDS_Store').touch(exist_ok=False)
        self.path.joinpath(' dir').mkdir()
        self.path.joinpath(' dir').joinpath(
            ':2eDS_Store').touch(exist_ok=False)

        clean_dir(self.path, execute=True)

        self.assertEqual(set(self.path.glob('**/*')),
                         set([self.path.joinpath('dir')]),
                         'files not removed: %s' % [x for x
                                                    in self.path.iterdir()])