def test_convert_type_none(self, log_mock): """ParserBase - Convert Type, NoneType Value""" schema = {'key': 'string'} record = {'key': None} assert_equal(ParserBase._convert_type(record, schema), True) assert_equal(record, {'key': None}) log_mock.assert_called_with( 'Skipping NoneType value in record for key: %s', 'key')
def test_convert_type_optionals(self, log_mock): """ParserBase - Convert Type, With Optionals Missing""" schema = {'required_key': 'string', 'optional_key': 'string'} optionals = {'optional_key'} record = {'required_key': 'required_value'} assert_equal(ParserBase._convert_type(record, schema, optionals), True) assert_equal(record, {'required_key': 'required_value'}) log_mock.assert_called_with( 'Skipping optional key not found in record: %s', 'optional_key')
def test_convert_type_unsupported_type(self, log_mock): """ParserBase - Convert Type, Unsupported Type""" schema = {'key': 'foobar'} record = {'key': 'foobarbaz'} assert_equal(ParserBase._convert_type(record, schema), False) assert_equal(record, {'key': 'foobarbaz'}) log_mock.assert_called_with( 'Unsupported value type in schema for key \'%s\': %s', 'key', 'foobar')
def test_convert_type_nested(self): """ParserBase - Convert Type, Nested""" schema = {'key': 'string', 'nested': {'key': 'integer'}} record = {'key': 'foo', 'nested': {'key': '100'}} assert_equal(ParserBase._convert_type(record, schema), True) assert_equal(record, {'key': 'foo', 'nested': {'key': 100}})
def test_convert_type_list(self): """ParserBase - Convert Type, Invalid List""" schema = {'key': []} record = {'key': 'not a list'} assert_equal(ParserBase._convert_type(record, schema), False) assert_equal(record, {'key': 'not a list'})
def test_convert_type_float_invalid(self): """ParserBase - Convert Type, Invalid Float""" schema = {'key': 'float'} record = {'key': 'not a float'} assert_equal(ParserBase._convert_type(record, schema), False) assert_equal(record, {'key': 'not a float'})
def test_convert_type_bool(self): """ParserBase - Convert Type, Boolean""" schema = {'key': 'boolean'} record = {'key': 'True'} assert_equal(ParserBase._convert_type(record, schema), True) assert_equal(record, {'key': True})
def test_convert_type_float(self): """ParserBase - Convert Type, Float""" schema = {'key': 'float'} record = {'key': '0.9'} assert_equal(ParserBase._convert_type(record, schema), True) assert_equal(record, {'key': 0.9})
def test_convert_type_int_invalid(self): """ParserBase - Convert Type, Invalid Int""" schema = {'key': 'integer'} record = {'key': 'not an int'} assert_equal(ParserBase._convert_type(record, schema), False) assert_equal(record, {'key': 'not an int'})
def test_convert_type_int(self): """ParserBase - Convert Type, Int""" schema = {'key': 'integer'} record = {'key': '100'} assert_equal(ParserBase._convert_type(record, schema), True) assert_equal(record, {'key': 100})
def test_convert_type_unicode_str(self): """ParserBase - Convert Type, Unicode Str""" schema = {'key': 'string'} record = {'key': u'\ue82a'} assert_equal(ParserBase._convert_type(record, schema), True) assert_equal(record, {'key': u'\ue82a'})
def test_convert_type_str(self): """ParserBase - Convert Type, Str""" schema = {'key': 'string'} record = {'key': 100} assert_equal(ParserBase._convert_type(record, schema), True) assert_equal(record, {'key': '100'})