Skip to content

Commit

Permalink
little pylint pass
Browse files Browse the repository at this point in the history
  • Loading branch information
lmichel authored and bsipocz committed May 7, 2024
1 parent 42c6570 commit 912a260
Show file tree
Hide file tree
Showing 13 changed files with 103 additions and 476 deletions.
43 changes: 29 additions & 14 deletions pyvo/mivot/seekers/annotation_seeker.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ def _rename_ref_and_join(self):
ele.tag = tag + '_' + str(cpt)
cpt += 1

def _name_match(self, name, expected):
@staticmethod
def _name_match(name, expected):
"""
Return true if name matches expected whatever the namespace
Parameters
Expand Down Expand Up @@ -240,11 +241,15 @@ def get_instance_by_dmtype(self, dmtype_pattern):
Format: {'dmtype': [instance], ...}
"""
retour = {Ele.GLOBALS: [], Ele.TEMPLATES: {}}
eset = XPath.x_path_contains(self._globals_block, ".//" + Ele.INSTANCE, Att.dmtype, dmtype_pattern)
eset = XPath.x_path_contains(self._globals_block,
".//" + Ele.INSTANCE,
Att.dmtype,
dmtype_pattern
)
retour[Ele.GLOBALS] = eset
for tableref, block in self._templates_blocks.items():
retour[Ele.TEMPLATES][tableref] = (
XPath.x_path_contains(block, ".//" + Ele.INSTANCE, Att.dmtype, dmtype_pattern))
for (tableref, block) in self._templates_blocks.items():
retour[Ele.TEMPLATES][tableref] = XPath.x_path_contains(block, './/'
+ Ele.INSTANCE, Att.dmtype, dmtype_pattern)
return retour

"""
Expand Down Expand Up @@ -273,7 +278,8 @@ def get_globals_instance_dmids(self):
List of @dmid of GLOBALS/INSTANCE
"""
retour = []
eset = XPath.x_path(self._globals_block, ".//" + Ele.INSTANCE + "[@" + Att.dmid + "]")
eset = XPath.x_path(self._globals_block,
".//" + Ele.INSTANCE + "[@" + Att.dmid + "]")
for ele in eset:
retour.append(ele.get(Att.dmid))
return retour
Expand All @@ -289,7 +295,9 @@ def get_globals_instance_by_dmid(self, dmid):
-------
dict: `~xml.etree.ElementTree.Element`
"""
eset = XPath.x_path(self._globals_block, ".//" + Ele.INSTANCE + "[@" + Att.dmid + "='" + dmid + "']")
eset = XPath.x_path(self._globals_block,
(".//" + Ele.INSTANCE + "[@" + Att.dmid + "='" + dmid + "']")
)
for ele in eset:
return ele
return None
Expand Down Expand Up @@ -323,7 +331,8 @@ def get_templates_instance_by_dmid(self, tableref, dmid):
templates_block = self.get_templates_block(tableref)
if templates_block is None:
return None
eset = XPath.x_path(templates_block, ".//" + Ele.INSTANCE + "[@" + Att.dmid + "='" + dmid + "']")
eset = XPath.x_path(templates_block,
".//" + Ele.INSTANCE + "[@" + Att.dmid + "='" + dmid + "']")
for ele in eset:
return ele
return None
Expand Down Expand Up @@ -427,13 +436,19 @@ def get_collection_item_by_primarykey(self, coll_dmid, key_value):
+ coll_dmid + "']/" + Ele.INSTANCE + "/" + Att.primarykey
+ "[@" + Att.value + "='" + key_value + "']")
if len(eset) == 0:
raise MivotElementNotFound(Ele.INSTANCE + " with " + Att.primarykey + f" = {key_value} in "
+ Ele.COLLECTION + " " + Att.dmid + f" {key_value} not found")
message = (f"{Ele.INSTANCE} with {Att.primarykey} = {key_value} in "
f"{Ele.COLLECTION} {Att.dmid} {key_value} not found"
)
raise MivotElementNotFound(message)
if len(eset) > 1:
raise MappingException("More than one " + Ele.INSTANCE + " with " + Att.primarykey
+ f" = {key_value} found in " + Ele.COLLECTION + " "
+ Att.dmid + f" {key_value}")
logger.debug(Ele.INSTANCE + " with " + Att.primarykey + "=%s found in " + Ele.COLLECTION + " "
message = (
f"More than one {Ele.INSTANCE} with {Att.primarykey}"
f" = {key_value} found in {Ele.COLLECTION} "
f"{Att.dmid} {key_value}"
)
raise MappingException(message)
logger.debug(Ele.INSTANCE + " with " + Att.primarykey + "=%s found in "
+ Ele.COLLECTION + " "
+ Att.dmid + "=%s", key_value, coll_dmid)
parent_map = {c: p for p in self._globals_block.iter() for c in p}
return parent_map[eset[0]]
2 changes: 1 addition & 1 deletion pyvo/mivot/seekers/resource_seeker.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@


@prototype_feature('MIVOT')
class ResourceSeeker(object):
class ResourceSeeker:
"""
This class provides multiple getters on resource tables.
Some methods are simple wrappers for external tools in order to have all
Expand Down
4 changes: 2 additions & 2 deletions pyvo/mivot/seekers/table_iterator.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def __init__(self, name, data_table):
# not used yet
self.row_filter = None

def _get_next_row(self):
def get_next_row(self):
"""
Return the next Numpy row or None.
The end of table exception usually returned by Numpy is trapped.
Expand All @@ -49,7 +49,7 @@ def _get_next_row(self):
except StopIteration:
return None

def _rewind(self):
def rewind(self):
"""
Set the pointer on the table-top, destroys the iterator actually.
"""
Expand Down
38 changes: 19 additions & 19 deletions pyvo/mivot/tests/test_mivot_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,30 @@

activate_features('MIVOT')


faze_dict = {
"dmtype": "EpochPosition",
"longitude": {
"dmtype": "RealQuantity",
"value": 52.2340018,
"unit": "deg",
"astropy_unit": {},
"ref": "RAICRS"
},
"latitude": {
"dmtype": "RealQuantity",
"value": 59.8937333,
"unit": "deg",
"astropy_unit": {},
"ref": "DEICRS"
},
}
"dmtype": "EpochPosition",
"longitude": {
"dmtype": "RealQuantity",
"value": 52.2340018,
"unit": "deg",
"astropy_unit": {},
"ref": "RAICRS"
},
"latitude": {
"dmtype": "RealQuantity",
"value": 59.8937333,
"unit": "deg",
"astropy_unit": {},
"ref": "DEICRS"
}
}


def test_mivot_viewer_constructor():
"""Test the class generation from a dict."""
mivot_object = MivotInstance(**faze_dict)
mivot_object = MivotInstance(**faze_dict)
assert mivot_object.longitude.value == 52.2340018
assert mivot_object.longitude.unit == "deg"
assert mivot_object.longitude.dmtype == "RealQuantity"
assert mivot_object.dmtype == "EpochPosition"


28 changes: 17 additions & 11 deletions pyvo/mivot/tests/test_mivot_instance_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
@pytest.mark.remote_data
def test_model_viewer3(votable_test, simple_votable):
"""
Recursively compare an XML element with an element of MIVOT class with the function recursive_xml_check.
Recursively compare an XML element with an element of MIVOT
class with the function recursive_xml_check.
This test run on 2 votables : votable_test and simple_votable.
"""
if check_astropy_version() is False:
Expand Down Expand Up @@ -47,22 +48,26 @@ def recusive_xml_check(xml_simple_votable, MivotInstance):
if value == '':
if child.tag == 'ATTRIBUTE':
recusive_xml_check(child,
getattr(MivotInstance, MivotInstance._remove_model_name
(child.get('dmrole'))))
getattr(MivotInstance,
MivotInstance._remove_model_name(
child.get('dmrole'))))
elif child.tag == 'INSTANCE':
recusive_xml_check(child, getattr(MivotInstance,
MivotInstance._remove_model_name
(child.get('dmrole'), True)))
else:
if child.tag == 'ATTRIBUTE':
recusive_xml_check(child, getattr(MivotInstance, MivotInstance._remove_model_name
(child.get('dmrole'))))
recusive_xml_check(child, getattr(MivotInstance,
MivotInstance._remove_model_name(
child.get('dmrole'))))
elif child.tag == 'INSTANCE':
recusive_xml_check(child, getattr(MivotInstance, MivotInstance._remove_model_name
(child.get('dmrole'), True)))
recusive_xml_check(child, getattr(MivotInstance,
MivotInstance._remove_model_name(
child.get('dmrole'), True)))
elif child.tag == 'COLLECTION':
recusive_xml_check(child, getattr(MivotInstance, MivotInstance._remove_model_name
(child.get('dmrole'))))
recusive_xml_check(child, getattr(MivotInstance,
MivotInstance._remove_model_name(
child.get('dmrole'))))
elif child.tag == 'COLLECTION':
for key, value in child.attrib.items():
assert len(getattr(MivotInstance,
Expand Down Expand Up @@ -125,8 +130,9 @@ def recursive_check(MivotInstance, **kwargs):
if isinstance(item, dict):
assert 'dmtype' in item.keys()
recursive_check(getattr(MivotInstance,
MivotInstance._remove_model_name(key))[nbr_item],
**item)
MivotInstance._remove_model_name(key))[nbr_item],
**item
)
nbr_item += 1
elif isinstance(value, dict) and 'value' not in value:
# for INSTANCE of INSTANCEs dmrole needs model_name
Expand Down
10 changes: 5 additions & 5 deletions pyvo/mivot/tests/test_user_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ def path_to_votable(data_path, data_sample_url):
os.remove(votable_path)




@pytest.mark.remote_data
def test_by_attribute(path_to_votable):
""" check that the mivot object attribute are correct """
Expand All @@ -54,7 +52,7 @@ def test_by_attribute(path_to_votable):
cpt += 1
assert cpt == 6
mivot_viewer.rewind()

ref = [-0.36042119, 0.22293899, -0.07592034, -0.21749947, -0.1281483, -0.28005255]
read = []
while mivot_viewer.next_row():
Expand All @@ -63,12 +61,13 @@ def test_by_attribute(path_to_votable):

assert read == ref


@pytest.mark.remote_data
def test_external_iterator(path_to_votable, delt_coo):
""" Checks the the values returned by MIVOT are
""" Checks the the values returned by MIVOT are
the same as those read by Astropy
"""
# parse the VOTable outside of the viewer
# parse the VOTable outside of the viewer
votable = parse(path_to_votable)
table = votable.resources[0].tables[0]
# init the viewer
Expand All @@ -82,5 +81,6 @@ def test_external_iterator(path_to_votable, delt_coo):
assert rec["RAICRS"] == mivot_object.longitude.value
assert rec["DEICRS"] == mivot_object.latitude.value


if __name__ == '__main__':
pytest.main()
Loading

0 comments on commit 912a260

Please sign in to comment.