示例#1
0
    def test_help_to_lines(self):
        spec = Spec('name', help='Single line.')
        assert spec.help_to_lines() == ['Single line.']

        spec.help = """
        Line 1
        Line 2
            Line 3
        """
        assert spec.help_to_lines() == ['Line 1', 'Line 2', '    Line 3']
示例#2
0
    def test_type_to_string(self):
        spec = Spec('name')

        assert spec.type_to_string(None) == 'null'
        assert spec.type_to_string(bool) == 'yes/no'
        assert spec.type_to_string(int) == '<number>'
        assert spec.type_to_string(float) == '<number>'
        assert spec.type_to_string(str) == '<text>'
示例#3
0
    def test_validate(self):
        spec = Spec('name', type=int)

        with pytest.raises(ValueError) as e:
            spec.validate('321')
        assert str(e.value) == 'Incorrect value for [name]: 321'

        # No errors here.
        spec.validate(123)
示例#4
0
 def test_to_lines(self):
     spec = Spec('name', help='line1\nline2', type=int)
     assert spec.to_lines() == ['line1', 'line2', 'Value: <number>']
示例#5
0
 def test_add_type_info(self):
     lines = []
     spec = Spec('name', type=int)
     spec.add_type_info(lines)
     assert lines == ['Value: <number>']
示例#6
0
 def test_convert_incorrect(self, value, type):
     spec = Spec('name', type=type)
     with pytest.raises(ValueError):
         spec.convert(value)
示例#7
0
 def test_convert(self, value, type, result):
     spec = Spec('name', type=type)
     assert spec.convert(value) == result
示例#8
0
 def test_do_validate(self, value, type, valid):
     spec = Spec('name', type=type)
     assert spec.do_validate(value) == valid
示例#9
0
 def test_construct_params(self):
     spec = Spec('name', 'help', dict)
     assert spec.name == 'name'
     assert spec.help == 'help'
     assert spec.type is dict
示例#10
0
 def test_construct(self):
     spec = Spec('name')
     assert spec.name == 'name'
     assert spec.help is None
     assert spec.type is None