def test_ignore__ignores(self): repo = TemplateRepo() self.tmpdir.mkdir('node_modules') self.tmpdir.mkdir('node_modules/hello') self.tmpdir.mkdir('.git') self.tmpdir.mkdir('hi') to_ignore = repo.ignore( str(self.tmpdir), [ # -- ignore: node_modules and all its children 'node_modules', 'node_modules/hello', 'node_modules/angular.ts', # -- ignore: .git and all its children '.git', '.git/hooks', '.git/whatever.json', # -- no ignore .ts 'hello.ts', 'hi/hello.ts', ]) assert set(to_ignore) == set([ '.git', '.git/hooks', '.git/whatever.json', 'node_modules', 'node_modules/hello', 'node_modules/angular.ts', ])
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']
def test_clone__makes_the_right_calls(self): clone = self.mocker.patch.object(Repo, 'clone') temp_dir = self.tmpdir.mkdir('123') self.mocker.patch.object(tempfile, 'mkdtemp').return_value = str(temp_dir) repo = TemplateRepo() repo.clone() assert clone.call_args_list == [call(str(temp_dir))]
def test_copy__deals_with_binary_files(self): source = self.tmpdir.join('hello.ico') source.write(b'\x00\x00\x01\x00\x02\x00\x10\x10\x00\x00', 'wb') destination = self.tmpdir.join('copy_hello.ico') repo = TemplateRepo() repo.copy('super', str(source), str(destination)) assert destination.read() == '\x00\x00\x01\x00\x02\x00\x10\x10\x00\x00'
def test_copy(self): source = self.tmpdir.join('hello.ts') source.write('hello there') destination = self.tmpdir.join('copy_hello.ts') repo = TemplateRepo() repo.copy('super', str(source), str(destination)) assert destination.read() == 'hello there'
def test_ignore__keeps(self): repo = TemplateRepo() self.tmpdir.mkdir('x') self.tmpdir.mkdir('x/y') to_ignore = repo.ignore( str(self.tmpdir), [ # -- exceptions 'a/karma.conf.js', 'a/browserslist', 'a/.npmignore', 'a/.gitkeep', # -- ts 'a/hi.ts', 'a/b/service.ts', # -- html 'b/app.html', 'b/c/what.html', # -- json 'hi.json', 'c/wat.json', # -- ico 'hi.ico', 'c/wat.ico', # -- css 'hi.css', 'c/wat.css', # -- all other directories 'x/what.json', 'x/y/whatever.ts', ]) # -- all to keep assert to_ignore == []
def test_copy__replaces_prefix(self): source = self.tmpdir.join('hello.ts') source.write( textwrap.dedent(''' hello __CLIENT_PREFIX__ __CLIENT_PREFIX__ is cool. ''')) destination = self.tmpdir.join('copy_hello.ts') repo = TemplateRepo() repo.copy('super', str(source), str(destination)) assert destination.read() == textwrap.dedent(''' hello super super is cool. ''')
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']))