From 02e7b83c7e74cfeea8961d8ec8cd9086e4a76162 Mon Sep 17 00:00:00 2001 From: JorisSynaeve Date: Thu, 28 May 2020 12:57:22 +0200 Subject: [PATCH 1/2] Change all "assert type(xxx) is yyy" to "assert isinstance(xxx,yyy)" in tests. --- tests/abstract.py | 88 +++++++++---------- tests/test_search.py | 2 +- tests/test_search_itp_formelestratigrafie.py | 2 +- tests/test_search_itp_gecodeerdelithologie.py | 2 +- .../test_search_itp_geotechnischecodering.py | 2 +- ...search_itp_hydrogeologischestratigrafie.py | 2 +- ...p_informelehydrogeologischestratigrafie.py | 2 +- .../test_search_itp_informelestratigrafie.py | 2 +- tests/test_search_itp_quartairstratigrafie.py | 2 +- tests/test_util_caching.py | 8 +- tests/test_util_hooks.py | 20 ++--- tests/test_util_owsutil.py | 22 ++--- 12 files changed, 77 insertions(+), 77 deletions(-) diff --git a/tests/abstract.py b/tests/abstract.py index 4f13cd91..ca01bd55 100644 --- a/tests/abstract.py +++ b/tests/abstract.py @@ -243,34 +243,34 @@ def test_get_fields(self, mp_wfs, mp_get_schema, """ fields = self.get_search_object().get_fields() - assert type(fields) is dict + assert isinstance(fields, dict) for field in fields: - assert type(field) is str + assert isinstance(field, str) f = fields[field] - assert type(f) is dict + assert isinstance(f, dict) assert 'name' in f - assert type(f['name']) is str + assert isinstance(f['name'],str) assert f['name'] == field assert 'definition' in f - assert type(f['name']) is str + assert isinstance(f['name'], str) assert 'type' in f - assert type(f['type']) is str + assert isinstance(f['type'], str) assert f['type'] in ['string', 'float', 'integer', 'date', 'datetime', 'boolean'] assert 'notnull' in f - assert type(f['notnull']) is bool + assert isinstance(f['notnull'], bool) assert 'query' in f - assert type(f['query']) is bool + assert isinstance(f['query'], bool) assert 'cost' in f - assert type(f['cost']) is int + assert isinstance(f['cost'], bool) assert f['cost'] > 0 if 'values' in f: @@ -278,22 +278,22 @@ def test_get_fields(self, mp_wfs, mp_get_schema, 'cost', 'definition', 'name', 'notnull', 'query', 'type', 'values'] - assert type(f['values']) is dict + assert isinstance(f['values'], dict) for v in f['values'].keys(): - assert type(f['values'][v]) is str or f[ + assert isinstance(f['values'][v], str) or f[ 'values'][v] is None if f['type'] == 'string': - assert type(v) is str + assert isinstance(v, str) elif f['type'] == 'float': - assert type(v) is float + assert isinstance(v, float) elif f['type'] == 'integer': - assert type(v) is int + assert isinstance(v, int) elif f['type'] == 'date': - assert type(v) is datetime.date + assert isinstance(v, datetime.date) elif f['type'] == 'boolean': - assert type(v) is bool + assert isinstance(v, bool) else: assert sorted(f.keys()) == ['cost', 'definition', 'name', 'notnull', 'query', 'type'] @@ -320,7 +320,7 @@ def test_search_both_location_query(self, mp_get_schema, query=self.get_valid_query_single(), return_fields=self.get_valid_returnfields()) - assert type(df) is DataFrame + assert isinstance(df, DataFrame) def test_search(self, mp_wfs, mp_get_schema, mp_remote_describefeaturetype, mp_remote_md, mp_remote_fc, mp_remote_wfs_feature, @@ -350,7 +350,7 @@ def test_search(self, mp_wfs, mp_get_schema, mp_remote_describefeaturetype, df = self.get_search_object().search( query=self.get_valid_query_single()) - assert type(df) is DataFrame + assert isinstance(df, DataFrame) assert list(df) == self.get_df_default_columns() @@ -410,7 +410,7 @@ def test_search_returnfields(self, mp_remote_wfs_feature): query=self.get_valid_query_single(), return_fields=self.get_valid_returnfields()) - assert type(df) is DataFrame + assert isinstance(df, DataFrame) assert list(df) == list(self.get_valid_returnfields()) @@ -431,7 +431,7 @@ def test_search_returnfields_subtype(self, mp_remote_wfs_feature): query=self.get_valid_query_single(), return_fields=self.get_valid_returnfields_subtype()) - assert type(df) is DataFrame + assert isinstance(df, DataFrame) assert list(df) == list(self.get_valid_returnfields_subtype()) @@ -457,7 +457,7 @@ def test_search_returnfields_order(self, mp_remote_wfs_feature): query=self.get_valid_query_single(), return_fields=rf) - assert type(df) is DataFrame + assert isinstance(df, DataFrame) assert list(df) == rf def test_search_wrongreturnfields(self): @@ -536,7 +536,7 @@ def test_search_extrareturnfields(self, mp_get_schema, query=self.get_valid_query_single(), return_fields=self.get_valid_returnfields_extra()) - assert type(df) is DataFrame + assert isinstance(df, DataFrame) assert list(df) == list(self.get_valid_returnfields_extra()) @@ -565,7 +565,7 @@ def test_search_sortby_valid(self, mp_get_schema, sort_by=SortBy([SortProperty( self.get_valid_returnfields_extra()[0])])) - assert type(df) is DataFrame + assert isinstance(df, DataFrame) def test_search_sortby_invalid(self, mp_get_schema, mp_remote_describefeaturetype, @@ -678,7 +678,7 @@ def test_get_fields_xsd_values(self, mp_remote_xsd): for f in xml_fields.values(): if 'xsd_type' in f: assert 'values' in fields[f['name']] - assert type(fields[f['name']]['values']) is dict + assert isinstance(fields[f['name']]['values'], dict) def test_get_fields_no_xsd(self): """Test whether no XML fields have an XSD type when no XSD schemas @@ -922,24 +922,24 @@ def test_get_fields(self): assert isinstance(fields, OrderedDict) for f in fields.keys(): - assert type(f) is str + assert isinstance(f, str) field = fields[f] assert isinstance(field, AbstractField) assert 'name' in field - assert type(field['name']) is str + assert isinstance(field['name'], str) assert field['name'] == f assert 'source' in field - assert type(field['source']) is str + assert isinstance(field['source'], str) assert field['source'] in ('wfs', 'xml') assert 'sourcefield' in field - assert type(field['sourcefield']) is str + assert isinstance(field['sourcefield'],str) assert 'type' in field - assert type(field['type']) is str + assert isinstance(field['type'], str) assert field['type'] in ['string', 'float', 'integer', 'date', 'datetime', 'boolean'] @@ -953,10 +953,10 @@ def test_get_fields(self): 'name', 'source', 'sourcefield', 'type'] elif field['source'] == 'xml': assert 'definition' in field - assert type(field['definition']) is str + assert isinstance(field['definition'], str) assert 'notnull' in field - assert type(field['notnull']) is bool + assert isinstance(field['notnull'], bool) if 'xsd_type' in field: assert sorted(field.keys()) == [ @@ -992,15 +992,15 @@ def test_from_wfs_element(self, wfs_feature): feature = self.get_type().from_wfs_element( wfs_feature, self.get_namespace()) - assert type(feature) is self.get_type() + assert isinstance(feature, self.get_type()) assert feature.pkey.startswith(self.get_pkey_base()) assert feature.pkey.startswith( build_dov_url('data/{}/'.format(feature.typename))) - assert type(feature.data) is dict - assert type(feature.subdata) is dict + assert isinstance(feature.data, dict) + assert isinstance(feature.subdata, dict) def test_get_df_array(self, wfs_feature, mp_dov_xml): """Test the get_df_array method. @@ -1025,22 +1025,22 @@ def test_get_df_array(self, wfs_feature, mp_dov_xml): df_array = feature.get_df_array() - assert type(df_array) is list + assert isinstance(df_array, list) for record in df_array: assert len(record) == len(fields) for value, field in zip(record, fields): if field['type'] == 'string': - assert type(value) is str or np.isnan(value) + assert isinstance(value, str) or np.isnan(value) elif field['type'] == 'float': - assert type(value) is float or np.isnan(value) + assert isinstance(value, float) or np.isnan(value) elif field['type'] == 'integer': - assert type(value) is int or np.isnan(value) + assert isinstance(value, int) or np.isnan(value) elif field['type'] == 'date': - assert type(value) is datetime.date or np.isnan(value) + assert isinstance(value, datetime.date) or np.isnan(value) elif field['type'] == 'boolean': - assert type(value) is bool or np.isnan(value) + assert isinstance(value, bool) or np.isnan(value) if field['name'].startswith('pkey') and not pd.isnull(value): assert value.startswith(build_dov_url('data/')) @@ -1078,7 +1078,7 @@ def test_from_wfs_str(self, wfs_getfeature): self.get_namespace()) for feature in features: - assert type(feature) is self.get_type() + assert isinstance(feature, self.get_type()) def test_from_wfs_bytes(self, wfs_getfeature): """Test the from_wfs method to construct objects from a WFS response, @@ -1094,7 +1094,7 @@ def test_from_wfs_bytes(self, wfs_getfeature): self.get_namespace()) for feature in features: - assert type(feature) is self.get_type() + assert isinstance(feature, self.get_type()) def test_from_wfs_tree(self, wfs_getfeature): """Test the from_wfs method to construct objects from a WFS response, @@ -1110,7 +1110,7 @@ def test_from_wfs_tree(self, wfs_getfeature): features = self.get_type().from_wfs(tree, self.get_namespace()) for feature in features: - assert type(feature) is self.get_type() + assert isinstance(feature, self.get_type()) def test_from_wfs_list(self, wfs_getfeature): """Test the from_wfs method to construct objects from a WFS response, @@ -1132,7 +1132,7 @@ def test_from_wfs_list(self, wfs_getfeature): features = self.get_type().from_wfs(fts, self.get_namespace()) for feature in features: - assert type(feature) is self.get_type() + assert isinstance(feature, self.get_type()) def test_missing_pkey(self): """Test initialising an object type with a pkey of 'None'. diff --git a/tests/test_search.py b/tests/test_search.py index 66d2aeac..9dd52d44 100644 --- a/tests/test_search.py +++ b/tests/test_search.py @@ -416,7 +416,7 @@ def test_get_description(mp_wfs, objectsearch): """ description = objectsearch.get_description() - assert type(description) is str + assert isinstance(description, str) assert len(description) > 0 diff --git a/tests/test_search_itp_formelestratigrafie.py b/tests/test_search_itp_formelestratigrafie.py index 1e2152c9..ac223dfd 100644 --- a/tests/test_search_itp_formelestratigrafie.py +++ b/tests/test_search_itp_formelestratigrafie.py @@ -218,7 +218,7 @@ def test_search_customreturnfields(self, mp_get_schema, return_fields=('pkey_interpretatie', 'pkey_boring', 'pkey_sondering')) - assert type(df) is DataFrame + assert isinstance(df, DataFrame) assert list(df) == ['pkey_interpretatie', 'pkey_boring', 'pkey_sondering'] diff --git a/tests/test_search_itp_gecodeerdelithologie.py b/tests/test_search_itp_gecodeerdelithologie.py index 9e145a24..37e6b813 100644 --- a/tests/test_search_itp_gecodeerdelithologie.py +++ b/tests/test_search_itp_gecodeerdelithologie.py @@ -223,7 +223,7 @@ def test_search_customreturnfields(self, mp_get_schema, query=self.get_valid_query_single(), return_fields=('pkey_interpretatie', 'pkey_boring')) - assert type(df) is DataFrame + assert isinstance(df, DataFrame) assert list(df) == ['pkey_interpretatie', 'pkey_boring'] diff --git a/tests/test_search_itp_geotechnischecodering.py b/tests/test_search_itp_geotechnischecodering.py index 75e78c22..674357fd 100644 --- a/tests/test_search_itp_geotechnischecodering.py +++ b/tests/test_search_itp_geotechnischecodering.py @@ -224,7 +224,7 @@ def test_search_customreturnfields(self, mp_get_schema, query=self.get_valid_query_single(), return_fields=('pkey_interpretatie', 'pkey_boring')) - assert type(df) is DataFrame + assert isinstance(df, DataFrame) assert list(df) == ['pkey_interpretatie', 'pkey_boring'] diff --git a/tests/test_search_itp_hydrogeologischestratigrafie.py b/tests/test_search_itp_hydrogeologischestratigrafie.py index dcb73ec0..5e079f15 100644 --- a/tests/test_search_itp_hydrogeologischestratigrafie.py +++ b/tests/test_search_itp_hydrogeologischestratigrafie.py @@ -218,7 +218,7 @@ def test_search_customreturnfields(self, mp_get_schema, query=self.get_valid_query_single(), return_fields=('pkey_interpretatie', 'pkey_boring')) - assert type(df) is DataFrame + assert isinstance(df, DataFrame) assert list(df) == ['pkey_interpretatie', 'pkey_boring'] diff --git a/tests/test_search_itp_informelehydrogeologischestratigrafie.py b/tests/test_search_itp_informelehydrogeologischestratigrafie.py index f262f061..bfeef710 100644 --- a/tests/test_search_itp_informelehydrogeologischestratigrafie.py +++ b/tests/test_search_itp_informelehydrogeologischestratigrafie.py @@ -201,7 +201,7 @@ def test_search_customreturnfields(self, mp_get_schema, return_fields=('pkey_interpretatie', 'pkey_boring', 'gemeente')) - assert type(df) is DataFrame + assert isinstance(df, DataFrame) assert list(df) == ['pkey_interpretatie', 'pkey_boring', 'gemeente'] diff --git a/tests/test_search_itp_informelestratigrafie.py b/tests/test_search_itp_informelestratigrafie.py index 09102488..1f0afd01 100644 --- a/tests/test_search_itp_informelestratigrafie.py +++ b/tests/test_search_itp_informelestratigrafie.py @@ -218,7 +218,7 @@ def test_search_customreturnfields(self, mp_get_schema, return_fields=('pkey_interpretatie', 'pkey_boring', 'pkey_sondering')) - assert type(df) is DataFrame + assert isinstance(df, DataFrame) assert list(df) == ['pkey_interpretatie', 'pkey_boring', 'pkey_sondering'] diff --git a/tests/test_search_itp_quartairstratigrafie.py b/tests/test_search_itp_quartairstratigrafie.py index 0f2b70ad..eea96d51 100644 --- a/tests/test_search_itp_quartairstratigrafie.py +++ b/tests/test_search_itp_quartairstratigrafie.py @@ -186,7 +186,7 @@ def test_search_customreturnfields(self, mp_get_schema, return_fields=('pkey_interpretatie', 'pkey_boring', )) - assert type(df) is DataFrame + assert isinstance(df, DataFrame) assert list(df) == ['pkey_interpretatie', 'pkey_boring', ] diff --git a/tests/test_util_caching.py b/tests/test_util_caching.py index d0e3f548..de80a45b 100644 --- a/tests/test_util_caching.py +++ b/tests/test_util_caching.py @@ -382,13 +382,13 @@ def test_return_type(self, plaintext_cache, mp_remote_xml): ref_data = plaintext_cache.get( build_dov_url('data/boring/2004-103984.xml')) - assert type(ref_data) is bytes + assert isinstance(ref_data, bytes) assert os.path.exists(cached_file) cached_data = plaintext_cache.get( build_dov_url('data/boring/2004-103984.xml')) - assert type(cached_data) is bytes + assert isinstance(cached_data, bytes) class TestGzipTextFileCacheCache(object): @@ -664,10 +664,10 @@ def test_return_type(self, gziptext_cache, mp_remote_xml): ref_data = gziptext_cache.get( build_dov_url('data/boring/2004-103984.xml')) - assert type(ref_data) is bytes + assert isinstance(ref_data, bytes) assert os.path.exists(cached_file) cached_data = gziptext_cache.get( build_dov_url('data/boring/2004-103984.xml')) - assert type(cached_data) is bytes + assert isinstance(cached_data, bytes) diff --git a/tests/test_util_hooks.py b/tests/test_util_hooks.py index 66047687..c0355727 100644 --- a/tests/test_util_hooks.py +++ b/tests/test_util_hooks.py @@ -121,21 +121,21 @@ class HookTypeTester(AbstractReadHook, AbstractInjectHook): def meta_received(self, url, response): assert url is not None assert response is not None - assert type(url) is str - assert type(response) is bytes + assert isinstance(url, str) + assert isinstance(response, bytes) def inject_meta_response(self, url): assert url is not None - assert type(url) is str + assert isinstance(url, str) def wfs_search_init(self, typename): assert typename is not None - assert type(typename) is str + assert isinstance(typename, str) def wfs_search_result(self, number_of_results): assert number_of_results is not None assert number_of_results > 0 - assert type(number_of_results) is int + assert isinstance(number_of_results, int) def wfs_search_result_received(self, query, features): assert query is not None @@ -147,20 +147,20 @@ def inject_wfs_getfeature_response(self, query): def xml_received(self, pkey_object, xml): assert pkey_object is not None assert xml is not None - assert type(pkey_object) is str - assert type(xml) is bytes + assert isinstance(pkey_object, str) + assert isinstance(xml, bytes) def inject_xml_response(self, pkey_object): assert pkey_object is not None - assert type(pkey_object) is str + assert isinstance(pkey_object, str) def xml_cache_hit(self, pkey_object): assert pkey_object is not None - assert type(pkey_object) is str + assert isinstance(pkey_object, str) def xml_downloaded(self, pkey_object): assert pkey_object is not None - assert type(pkey_object) is str + assert isinstance(pkey_object, str) class HookInjecter(AbstractReadHook, AbstractInjectHook): diff --git a/tests/test_util_owsutil.py b/tests/test_util_owsutil.py index 300f14b6..7897867d 100644 --- a/tests/test_util_owsutil.py +++ b/tests/test_util_owsutil.py @@ -174,40 +174,40 @@ def test_get_remote_featurecatalogue(self, mp_remote_fc): build_dov_url('geonetwork/srv/nl/csw'), 'c0cbd397-520f-4ee1-aca7-d70e271eeed6') - assert type(fc) is dict + assert isinstance(fc, dict) assert 'definition' in fc - assert type(fc['definition']) is str + assert isinstance(fc['definition'], str) assert 'attributes' in fc - assert type(fc['attributes']) is dict + assert isinstance(fc['attributes'], str) attrs = fc['attributes'] if len(attrs) > 0: for attr in attrs.values(): - assert type(attr) is dict + assert isinstance(attr, dict) assert 'definition' in attr - assert type(attr['definition']) is str + assert isinstance(attr['definition'], str) assert 'values' in attr if attr['values'] is not None: - assert type(attr['values']) is dict + assert isinstance(attr['values'], dict) for v in attr['values'].keys(): - assert type(v) is str - assert type(attr['values'][v]) is str or \ + assert isinstance(v, str) + assert isinstance(attr['values'][v], str) or \ attr['values'][v] is None assert len(attr['values'].keys()) == len( set(attr['values'].keys())) assert 'multiplicity' in attr mp = attr['multiplicity'] - assert type(mp) is tuple + assert isinstance(mp, tuple) assert len(mp) == 2 assert mp[0] in (0, 1) - assert (type(mp[1]) is int and mp[1] > 0) or mp[1] == 'Inf' + assert (isinstance(mp[1], int) and mp[1] > 0) or mp[1] == 'Inf' def test_get_remote_featurecataloge_baduuid(self, mp_remote_fc_notfound): """Test the owsutil.get_remote_featurecatalogue method with an @@ -238,7 +238,7 @@ def test_get_remote_metadata(self, md_metadata): in the ISO 19115/19139 format. """ - assert type(md_metadata) is MD_Metadata + assert isinstance(md_metadata,MD_Metadata) def test_wfs_build_getfeature_request_onlytypename(self): From c2943ebf7deacb94cbcdaf210d22124b0e98c762 Mon Sep 17 00:00:00 2001 From: JorisSynaeve Date: Thu, 28 May 2020 13:23:55 +0200 Subject: [PATCH 2/2] Fix test failures --- tests/abstract.py | 2 +- tests/test_util_owsutil.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/abstract.py b/tests/abstract.py index ca01bd55..5035fb2e 100644 --- a/tests/abstract.py +++ b/tests/abstract.py @@ -270,7 +270,7 @@ def test_get_fields(self, mp_wfs, mp_get_schema, assert isinstance(f['query'], bool) assert 'cost' in f - assert isinstance(f['cost'], bool) + assert isinstance(f['cost'], int) assert f['cost'] > 0 if 'values' in f: diff --git a/tests/test_util_owsutil.py b/tests/test_util_owsutil.py index 7897867d..c065dd4b 100644 --- a/tests/test_util_owsutil.py +++ b/tests/test_util_owsutil.py @@ -180,7 +180,7 @@ def test_get_remote_featurecatalogue(self, mp_remote_fc): assert isinstance(fc['definition'], str) assert 'attributes' in fc - assert isinstance(fc['attributes'], str) + assert isinstance(fc['attributes'], dict) attrs = fc['attributes'] if len(attrs) > 0: