def test_collect_writers_overwrite_true(self): tree = spec.Tree(base_directory=self.enviroment_directory) tree.files.add_files( spec.File(path='a.txt', content='acontent'), spec.File(path='b.txt', content='bcontent'), ) with open(os.path.join(self.output_directory, 'a.txt'), 'w') as f: f.write('x') skipped_writers, writers = tree.collect_writers( output_directory=self.output_directory, overwrite=True) self.assertEqual(len(skipped_writers), 0) self.assertEqual(len(writers), 2) self.assertEqual(writers[0].file.path, 'a.txt') self.assertEqual(writers[1].file.path, 'b.txt')
def test_deserialize_templatepath(self): file = spec.File(path='mock') file.deserialize(data={'templatepath': 'the/template'}) self.assertEqual(file.content, None) self.assertEqual(file.contentpath, None) self.assertEqual(file.template, None) self.assertEqual(file.templatepath, 'the/template')
def test_deserialize_content(self): file = spec.File(path='mock') file.deserialize(data={'content': 'thecontent'}) self.assertEqual(file.content, 'thecontent') self.assertEqual(file.contentpath, None) self.assertEqual(file.template, None) self.assertEqual(file.templatepath, None)
def test_deserialize_empty_data(self): file = spec.File(path='mock') file.deserialize(data={}) self.assertEqual(file.content, None) self.assertEqual(file.contentpath, None) self.assertEqual(file.template, None) self.assertEqual(file.templatepath, None)
def test_get_content_template(self): file = spec.File(path='mock') file.deserialize(data={'template': 'a = {{{ a }}}'}) template_enviroment = template.make_environment( base_directory=self.enviroment_directory, variables={'a': 10}) self.assertEqual( file.get_content(template_environment=template_enviroment), 'a = 10')
def test_get_content_content(self): file = spec.File(path='mock') file.deserialize(data={'content': 'thecontent'}) template_enviroment = template.make_environment( base_directory=self.enviroment_directory, variables={}) self.assertEqual( file.get_content(template_environment=template_enviroment), 'thecontent')
def test_get_output_path(self): file = spec.File(path='{{{testvariable1}}}/{{{testvariable2}}}') template_enviroment = template.make_environment( base_directory=self.enviroment_directory, variables={ 'testvariable1': 'a', 'testvariable2': 'b' }) self.assertEqual( file.get_output_path(template_environment=template_enviroment), 'a/b')
def test_get_content_contentpath(self): file = spec.File(path='mock') file.deserialize(data={'contentpath': 'testfile.txt'}) with open(os.path.join(self.enviroment_directory, 'testfile.txt'), 'w') as f: f.write('hello') f.close() template_enviroment = template.make_environment( base_directory=self.enviroment_directory, variables={}) self.assertEqual( file.get_content(template_environment=template_enviroment), 'hello')
def test_len(self): files = spec.Files() files._files = [spec.File(path='a'), spec.File(path='b')] self.assertEqual(len(files), 2)
def test_iter(self): files = spec.Files() file1 = spec.File(path='a') file2 = spec.File(path='a') files._files = [file1, file2] self.assertEqual(list(files), [file1, file2])