Exemple #1
0
 def test_clear(self):
     cache = spec.SpecCache()
     cache.specs = OrderedDict([
         ('a', spec.Tree(base_directory='/mock1')),
         ('b', spec.Tree(base_directory='/mock2')),
     ])
     cache.clear()
     self.assertEqual(cache.specs, OrderedDict())
Exemple #2
0
 def test_add_specs(self):
     cache = spec.SpecCache()
     tree1 = spec.Tree(base_directory='/mock1',
                       context='thecontext',
                       id='mock1')
     tree2 = spec.Tree(base_directory='/mock2',
                       context='thecontext',
                       id='mock2')
     cache.add_specs(tree1, tree2)
     self.assertEqual(len(cache.specs), 2)
     self.assertEqual(cache.specs['thecontext.mock1'], tree1)
     self.assertEqual(cache.specs['thecontext.mock2'], tree2)
Exemple #3
0
 def test_validate_spec_invalid_context(self):
     tree = spec.Tree(**self.__make_kwargs(context='two words'))
     with self.assertRaisesRegex(
             exceptions.SpecValidationError,
             '^context: Must be a lowercase single word containing only a-z and numbers.$'
     ):
         tree.validate_spec()
Exemple #4
0
 def test_get_by_id_valid_id(self):
     cache = spec.SpecCache()
     tree = spec.Tree(base_directory='/mock',
                      context='thecontext',
                      id='mock')
     cache.add_spec(tree)
     self.assertEqual(cache.get_spec('thecontext.mock'), tree)
Exemple #5
0
 def test_add_spec(self):
     cache = spec.SpecCache()
     tree = spec.Tree(base_directory='/mock',
                      context='thecontext',
                      id='mock')
     cache.add_spec(tree)
     self.assertEqual(cache.specs['thecontext.mock'], tree)
Exemple #6
0
 def test_deserialize_empty_data(self):
     tree = spec.Tree(base_directory=self.enviroment_directory)
     tree.deserialize(data={})
     self.assertEqual(tree.id, None)
     self.assertEqual(tree.title, None)
     self.assertEqual(tree.description, None)
     self.assertEqual(len(tree.variables), 0)
     self.assertEqual(len(tree.files), 0)
Exemple #7
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')
Exemple #8
0
 def test_deserialize_with_data(self):
     tree = spec.Tree(base_directory=self.enviroment_directory)
     tree.deserialize(
         data={
             'id':
             'mockid',
             'title':
             'thetitle',
             'description':
             'thedescription',
             'files':
             OrderedDict([
                 ('a', {
                     'content': '1'
                 }),
                 ('b', {
                     'content': '2'
                 }),
             ]),
             'variables':
             OrderedDict([('testvariable1', {}), ('testvariable2', {})]),
             'postprocess_files':
             OrderedDict([('append_text', {
                 'text': 'suffix'
             })])
         })
     self.assertEqual(tree.id, 'mockid')
     self.assertEqual(tree.title, 'thetitle')
     self.assertEqual(tree.description, 'thedescription')
     self.assertEqual(len(tree.variables), 2)
     self.assertEqual(
         tree.variables.get_variable('testvariable1').name, 'testvariable1')
     self.assertEqual(
         tree.variables.get_variable('testvariable2').name, 'testvariable2')
     self.assertEqual(len(tree.files), 2)
     self.assertEqual(tree.files._files[0].path, 'a')
     self.assertEqual(tree.files._files[1].path, 'b')
     self.assertEqual(len(tree.postprocess_files), 1)
Exemple #9
0
 def test_validate_spec_no_context(self):
     tree = spec.Tree(**self.__make_kwargs(context=None))
     with self.assertRaisesRegex(exceptions.SpecValidationError,
                                 '^context: This attribute is required.$'):
         tree.validate_spec()