def test__get_dtypes_error_subtype_id(self): """Test get data types with an invalid id subtype.""" # Setup table_meta = { 'fields': { 'item': {'type': 'id', 'subtype': 'boolean'} } } metadata = Mock(spec=Metadata) metadata.get_table_meta.return_value = table_meta metadata._DTYPES = Metadata._DTYPES # Run with pytest.raises(ValueError): Metadata._get_dtypes(metadata, 'test', ids=True)
def test__get_dtypes_error_id(self): """Test get data types with an id that is not a primary or foreign key.""" # Setup table_meta = { 'fields': { 'item': {'type': 'id'} } } metadata = Mock(spec=Metadata) metadata.get_table_meta.return_value = table_meta metadata._DTYPES = Metadata._DTYPES # Run with pytest.raises(ValueError): Metadata._get_dtypes(metadata, 'test', ids=True)
def test__get_dtypes_error_invalid_type(self): """Test get data types with an invalid type.""" # Setup table_meta = { 'fields': { 'item': {'type': 'unknown'} } } metadata = Mock(spec=Metadata) metadata.get_table_meta.return_value = table_meta metadata._DTYPES = Metadata._DTYPES # Run with pytest.raises(ValueError): Metadata._get_dtypes(metadata, 'test')
def test__get_dtypes_error_subtype_numerical(self): """Test get data types with an invalid numerical subtype.""" # Setup table_meta = { 'fields': { 'item': {'type': 'numerical', 'subtype': 'boolean'} } } # Run and asserts metadata = Mock(spec=Metadata) metadata.get_table_meta.return_value = table_meta with pytest.raises(ValueError): Metadata._get_dtypes(metadata, 'test')
def test__get_dtypes_no_ids(self): """Test get data types excluding ids.""" # Setup table_meta = { 'fields': { 'item 0': {'type': 'id', 'subtype': 'integer'}, 'item 1': {'type': 'numerical', 'subtype': 'integer'}, 'item 2': {'type': 'numerical', 'subtype': 'float'}, 'item 3': {'type': 'categorical'}, 'item 4': {'type': 'boolean'}, 'item 5': {'type': 'datetime'}, } } metadata = Mock(spec=Metadata) metadata.get_table_meta.return_value = table_meta metadata._DTYPES = Metadata._DTYPES # Run result = Metadata._get_dtypes(metadata, 'test') # Asserts expected = { 'item 1': int, 'item 2': float, 'item 3': np.object, 'item 4': bool, 'item 5': np.datetime64, } assert result == expected