Ejemplo n.º 1
0
 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')
Ejemplo n.º 2
0
 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')
Ejemplo n.º 3
0
 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)
Ejemplo n.º 4
0
 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)
Ejemplo n.º 5
0
 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')
Ejemplo n.º 6
0
 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')
Ejemplo n.º 7
0
 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')
Ejemplo n.º 8
0
 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')
Ejemplo n.º 9
0
 def test_len(self):
     files = spec.Files()
     files._files = [spec.File(path='a'), spec.File(path='b')]
     self.assertEqual(len(files), 2)
Ejemplo n.º 10
0
 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])