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']
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>'
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)
def test_to_lines(self): spec = Spec('name', help='line1\nline2', type=int) assert spec.to_lines() == ['line1', 'line2', 'Value: <number>']
def test_add_type_info(self): lines = [] spec = Spec('name', type=int) spec.add_type_info(lines) assert lines == ['Value: <number>']
def test_convert_incorrect(self, value, type): spec = Spec('name', type=type) with pytest.raises(ValueError): spec.convert(value)
def test_convert(self, value, type, result): spec = Spec('name', type=type) assert spec.convert(value) == result
def test_do_validate(self, value, type, valid): spec = Spec('name', type=type) assert spec.do_validate(value) == valid
def test_construct_params(self): spec = Spec('name', 'help', dict) assert spec.name == 'name' assert spec.help == 'help' assert spec.type is dict
def test_construct(self): spec = Spec('name') assert spec.name == 'name' assert spec.help is None assert spec.type is None