Пример #1
0
    def test_copy_to__cleans_up_before_copy(self):

        source_dir = self.tmpdir.mkdir('source')
        d = source_dir.mkdir('d')
        f = d.join('f.md')
        f.write('f')

        destination_dir = self.tmpdir.mkdir('destination')

        # -- should be kept
        git_dir = destination_dir.mkdir('.git')
        git_dir.join('hook').write('hook it')

        # -- should be removed
        dd = destination_dir.mkdir('dd')
        dd.join('hi.txt').write('hello')
        destination_dir.join('root.js').write('root it')

        self.mocker.patch.object(tempfile,
                                 'mkdtemp').return_value = str(source_dir)

        repo = TemplateRepo()

        repo.copy_to(str(destination_dir), 'extra')

        assert set(os.listdir(destination_dir)) == set(['d', '.git'])
        assert os.listdir(destination_dir.join('d')) == ['f.md']
        assert os.listdir(destination_dir.join('.git')) == ['hook']
Пример #2
0
    def test_copy_to__ignores_and_keeps(self):

        source_dir = self.tmpdir.mkdir('source')
        d_0 = source_dir.mkdir('d_0')

        f_0_0 = d_0.join('f_0_0.md')
        f_0_0.write('f_0_0')

        f_0_1 = d_0.join('f_0_1.js')  # noqa - will be ignored
        f_0_1.write('f_0_1')

        d_0_0 = d_0.mkdir('d_0_0')

        f_0_0_0 = d_0_0.join('f_0_0_0.json')
        f_0_0_0.write('f_0_0_0')

        f_0_0_1 = d_0_0.join('f_0_0_1.ts')
        f_0_0_1.write('f_0_0_1')

        d_1 = source_dir.mkdir('d_1')

        f_1_0 = d_1.join('f_1_0.ico')
        f_1_0.write('f_1_0')

        self.mocker.patch.object(tempfile,
                                 'mkdtemp').return_value = str(source_dir)

        destination_dir = self.tmpdir.mkdir('destination')
        repo = TemplateRepo()

        repo.copy_to(str(destination_dir), 'extra')

        assert set(os.listdir(destination_dir)) == set(['d_0', 'd_1'])
        assert (set(os.listdir(destination_dir.join('d_0'))) == set(
            ['f_0_0.md', 'd_0_0']))
        assert (set(os.listdir(destination_dir.join('d_0/d_0_0'))) == set(
            ['f_0_0_0.json', 'f_0_0_1.ts']))
        assert (set(os.listdir(destination_dir.join('d_1'))) == set(
            ['f_1_0.ico']))