def test_do_prompt_empty_default(self): """Tests Var.do_prompt() with empty default""" resps = [''] self.input_mock.side_effect = lambda x: resps.pop(0) var = Var('foo', default='') self.assertEqual(var.do_prompt(), '') self.assertEqual(self.input_mock.call_count, 1)
class Jinja(Static): """Skeleton dynamic content using jinja syntax""" src = 'skeletons/jinja' use_jinja = True variables = [ Var('foo'), Var('bar'), ]
def test_do_prompt(self): """Tests Var.do_prompt() """ resps = ['', 'bar'] self.input_mock.side_effect = lambda x: resps.pop(0) var = Var('foo') self.assertEqual(var.do_prompt(), 'bar') self.assertEqual(self.input_mock.call_count, 2)
def test_pep8_var_name(self): """Tests long string formatting of options added by vars_to_optparser. All lower case with hyphen instead of underscore """ parser = vars_to_optparser([Var('Foo'), Var('foo_bar')]) self.assertEqual(parser.get_option('--foo').dest, 'Foo') self.assertEqual(parser.get_option('--foo-bar').dest, 'foo_bar')
def test_prompt(self): """Tests Var.prompt()""" var = Var('foo') self.assertEqual(var.prompt, 'Enter Foo: ')
class Required(Static): """Just a ${FileName}.txt file""" src = "skeletons/required" variables = [Var('file_name')]
class DynamicContent(Static): """Skeleton dynamic content (bar/bax.txt_tmpl)""" src = 'skeletons/dynamic-content' variables = [ Var('baz', 'Dummy variable'), ]
def test_default_metavar(self): """Tests option's metavar""" parser = vars_to_optparser([Var('Foo'), Var('bar_name')]) self.assertEqual(parser.get_option('--foo').metavar, 'FOO') self.assertEqual(parser.get_option('--bar-name').metavar, 'NAME')
def test_prompt_empty_default(self): """Tests Var.prompt with empty default""" var = Var('foo', default='') self.assertEqual(var.prompt, """Enter Foo ['']: """)
def test_prompt_with_default(self): """Tests Var.prompt with default""" var = Var('foo', default='baz') self.assertEqual(var.prompt, """Enter Foo ['baz']: """)
def test_pep8_name(self): """Tests Var full description (missing description)""" var = Var('foo_bar') self.assertEqual(var.full_description, 'Foo Bar')
def test_basic_full_description(self): """Tests Var full description (missing description)""" var = Var('foo') self.assertEqual(var.full_description, 'Foo')
def test_full_description(self): """Tests Var full description (complete)""" var = Var('foo', description='dummy var') self.assertEqual(var.full_description, 'Foo (dummy var)')
def test_repr(self): """Tests Var representation""" var = Var('foo', description='dummy var') self.assertEqual(repr(var), '<Var foo default=None>')
class WithRequirement(Skeleton): """Skeleton with other skeleton required""" variables = [Var('foo', default=1)] required_skeletons = [ WithDefault, ]
class WithDefault(Skeleton): """Skeleton with variables with default""" variables = [Var('foo'), Var('bar', default=2), Var('baz')]