Пример #1
0
 def test_validate_spec_invalid_context(self):
     snippet = spec.Snippet(**self.__make_kwargs(context='two words'))
     with self.assertRaisesRegex(
             exceptions.SpecValidationError,
             '^context: Must be a lowercase single word containing only a-z and numbers.$'
     ):
         snippet.validate_spec()
Пример #2
0
    def test_get_content_from_template(self):
        snippet = spec.Snippet(base_directory=self.enviroment_directory,
                               template='a = {{{ a }}}',
                               variables=spec.Variables(
                                   spec.Variable(name='a', value=10)))

        self.assertEqual(snippet.render(), 'a = 10')
Пример #3
0
 def test_deserialize_with_data(self):
     snippet = spec.Snippet(base_directory=self.enviroment_directory)
     snippet.deserialize(
         data={
             'id':
             'mockid',
             'title':
             'thetitle',
             'description':
             'thedescription',
             'variables':
             OrderedDict([('testvariable1', {}), ('testvariable2', {})]),
             'template':
             'test',
             'templatepath':
             'test.codeskeleton.txt',
         })
     self.assertEqual(snippet.id, 'mockid')
     self.assertEqual(snippet.title, 'thetitle')
     self.assertEqual(snippet.description, 'thedescription')
     self.assertEqual(len(snippet.variables), 2)
     self.assertEqual(
         snippet.variables.get_variable('testvariable1').name,
         'testvariable1')
     self.assertEqual(
         snippet.variables.get_variable('testvariable2').name,
         'testvariable2')
     self.assertEqual(snippet.template, 'test')
     self.assertEqual(snippet.templatepath, 'test.codeskeleton.txt')
Пример #4
0
 def test_validate_spec_no_template(self):
     snippet = spec.Snippet(
         **self.__make_kwargs(template=None, templatepath=''))
     with self.assertRaisesRegex(
             exceptions.SpecValidationError,
             '^template|templatepath: "template" or "templatepath" is required$'
     ):
         snippet.validate_spec()
Пример #5
0
 def test_deserialize_empty_data(self):
     snippet = spec.Snippet(base_directory=self.enviroment_directory)
     snippet.deserialize(data={})
     self.assertEqual(snippet.id, None)
     self.assertEqual(snippet.title, None)
     self.assertEqual(snippet.description, None)
     self.assertEqual(len(snippet.variables), 0)
     self.assertEqual(snippet.template, None)
     self.assertEqual(snippet.templatepath, None)
Пример #6
0
 def test_validate_spec_no_context(self):
     snippet = spec.Snippet(**self.__make_kwargs(context=None))
     with self.assertRaisesRegex(exceptions.SpecValidationError,
                                 '^context: This attribute is required.$'):
         snippet.validate_spec()