Skip to content

Commit

Permalink
Add creation of input-output-map entry
Browse files Browse the repository at this point in the history
  • Loading branch information
tcezard committed Feb 14, 2019
1 parent a8abeda commit 8515956
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 6 deletions.
34 changes: 29 additions & 5 deletions pyclarity_lims/descriptors.py
Expand Up @@ -664,16 +664,40 @@ def _get_dict(self, lims, node):
result[key] = node.attrib[key]
except KeyError:
pass
for uri in ['uri', 'post-process-uri']:
try:
result[uri] = Artifact(lims, uri=node.attrib[uri])
except KeyError:
pass
for uri in ['uri', 'post-process-uri']:
try:
result[uri] = Artifact(lims, uri=node.attrib[uri])
except KeyError:
pass
node = node.find('parent-process')
if node is not None:
result['parent-process'] = Process(lims, node.attrib['uri'])
return result

def _set_dict(self, element, value_dict):
for key in ['limsid', 'output-type', 'output-generation-type']:
if key in value_dict:
element.attrib[key] = value_dict[key]
for key in ['uri', 'post-process-uri']:
if key in value_dict:
element.attrib[key] = value_dict[key].uri
if 'parent-process' in value_dict:
node = ElementTree.SubElement(element, 'parent-process')
node.attrib['uri'] = value_dict['parent-process'].uri

def _create_new_node(self, value ):
if not isinstance(value, tuple):
raise TypeError('You need to provide a tuple not %s' % (type(value)))
if len(value) != 2:
raise TypeError('You need to provide a tuple with 2 values, found %s' % len(value))
input_dict, output_dict = value
node = ElementTree.Element(self.tag)
input_element = ElementTree.SubElement(node, 'input')
output_element = ElementTree.SubElement(node, 'output')
self._set_dict(input_element, input_dict)
self._set_dict(output_element, output_dict)
return node


class OutputPlacementList(TagXmlList):
"""This is a list of output placements as found in the StepPlacement. The list contains tuples organised as follows:
Expand Down
22 changes: 21 additions & 1 deletion tests/test_descriptors.py
Expand Up @@ -11,7 +11,7 @@
StringDictionaryDescriptor, IntegerDescriptor, BooleanDescriptor, UdfDictionary, EntityDescriptor, \
InputOutputMapList, EntityListDescriptor, PlacementDictionary, EntityList, SubTagDictionary, ExternalidList,\
XmlElementAttributeDict, XmlAttributeList, XmlReagentLabelList, XmlPooledInputDict, XmlAction, QueuedArtifactList
from pyclarity_lims.entities import Artifact, ProtocolStep, Container
from pyclarity_lims.entities import Artifact, ProtocolStep, Container, Process
from pyclarity_lims.lims import Lims
from tests import elements_equal

Expand Down Expand Up @@ -663,6 +663,26 @@ def test___get__(self):
assert sorted(res[0][0].keys()) == sorted(expected_keys_input)
assert sorted(res[0][1].keys()) == sorted(expected_keys_ouput)

def test_create(self):
et = ElementTree.fromstring("""<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<test-entry xmlns:udf="http://genologics.com/ri/userdefined">
</test-entry>""")
lims = Mock(cache={})
instance = Mock(root=et, lims=lims)
res = self.IO_map.__get__(instance, None)
input_dict = {'uri': Artifact(lims, uri='input_uri'), 'limsid': 'a1', 'parent-process': Process(lims, uri='p_uri')}
output_dict = {'uri': Artifact(lims, uri='output_uri'), 'limsid': 'a2', 'output-type': 'PerInput'}
res.append((input_dict, output_dict))
assert len(et) == 1
node = et.find('input-output-map')
assert len(node) == 2 # input and output
assert node.find('input').attrib['uri'] == 'input_uri'
assert node.find('input').attrib['limsid'] == 'a1'
assert node.find('input').find('parent-process').attrib['uri'] == 'p_uri'
assert node.find('output').attrib['uri'] == 'output_uri'
assert node.find('output').attrib['limsid'] == 'a2'
assert node.find('output').attrib['output-type'] == 'PerInput'


class TestExternalidList(TestCase):
def setUp(self):
Expand Down

0 comments on commit 8515956

Please sign in to comment.