Skip to content

Commit

Permalink
More unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
scaramallion committed Feb 1, 2017
1 parent 77fa69f commit 0561a36
Show file tree
Hide file tree
Showing 4 changed files with 186 additions and 93 deletions.
91 changes: 38 additions & 53 deletions pynetdicom3/applicationentity.py
Original file line number Diff line number Diff line change
Expand Up @@ -731,33 +731,28 @@ def scu_supported_sop(self, sop_list):
self._scu_supported_sop = []

if not isinstance(sop_list, list):
raise ValueError("scu_supported_sop must be a list of SOP " \
raise TypeError("scu_supported_sop must be a list of SOP " \
"classes.")

try:
for sop_class in sop_list:
if isinstance(sop_class, str):
sop_uid = UID(sop_class)
elif isinstance(sop_class, UID):
sop_uid = sop_class
elif isclass(sop_class) and 'UID' in sop_class.__dict__:
sop_uid = UID(sop_class.UID)
elif isinstance(sop_class, bytes):
sop_uid = UID(sop_class.decode('utf-8'))
else:
continue
for sop_class in sop_list:
if isinstance(sop_class, str):
sop_uid = UID(sop_class)
elif isclass(sop_class) and 'UID' in sop_class.__dict__:
sop_uid = UID(sop_class.UID)
elif isinstance(sop_class, bytes):
sop_uid = UID(sop_class.decode('utf-8'))
else:
continue

try:
sop_uid.is_valid()
except InvalidUID:
continue
try:
sop_uid.is_valid()
except InvalidUID:
continue

self._scu_supported_sop.append(sop_uid)
self._scu_supported_sop.append(sop_uid)

if sop_list != [] and self._scu_supported_sop == []:
raise ValueError("No valid SCU SOP classes were supplied")
except TypeError:
raise ValueError("scu_sop_class must be a list")
if sop_list != [] and self._scu_supported_sop == []:
raise TypeError("No valid SCU SOP classes were supplied")

@property
def scp_supported_sop(self):
Expand All @@ -782,40 +777,31 @@ def scp_supported_sop(self, sop_list):
# pylint: disable=attribute-defined-outside-init
self._scp_supported_sop = []
if not isinstance(sop_list, list):
raise ValueError("scp_supported_sop must be a list of SOP " \
raise TypeError("scp_supported_sop must be a list of SOP " \
"classes.")

try:
for sop_class in sop_list:

if isinstance(sop_class, str):
sop_uid = UID(sop_class)
elif isinstance(sop_class, UID):
sop_uid = sop_class
elif isinstance(sop_class, bytes):
sop_uid = UID(sop_class.decode('utf-8'))
elif isclass(sop_class):
if 'UID' in sop_class.__dict__:
sop_uid = sop_class.UID
else:
continue
elif isinstance(sop_class, bytes):
sop_uid = UID(sop_class.decode('utf-8'))
for sop_class in sop_list:
if isinstance(sop_class, str):
sop_uid = UID(sop_class)
elif isinstance(sop_class, bytes):
sop_uid = UID(sop_class.decode('utf-8'))
elif isclass(sop_class):
if 'UID' in sop_class.__dict__:
sop_uid = sop_class.UID
else:
continue
else:
continue

try:
sop_uid.is_valid()
except InvalidUID:
continue

self._scp_supported_sop.append(sop_uid)
try:
sop_uid.is_valid()
except InvalidUID:
continue

if sop_list != [] and self._scp_supported_sop == []:
raise ValueError("No valid SCP SOP classes were supplied")
self._scp_supported_sop.append(sop_uid)

except TypeError:
raise ValueError("scp_sop_class must be a list")
if sop_list != [] and self._scp_supported_sop == []:
raise TypeError("No valid SCP SOP classes were supplied")

@property
def transfer_syntaxes(self):
Expand All @@ -833,8 +819,6 @@ def transfer_syntaxes(self, transfer_syntaxes):
for syntax in transfer_syntaxes:
if isinstance(syntax, str):
sop_uid = UID(syntax)
elif isinstance(syntax, UID):
sop_uid = syntax
elif isinstance(syntax, bytes):
sop_uid = UID(syntax.decode('utf-8'))
else:
Expand Down Expand Up @@ -873,7 +857,8 @@ def on_user_identity_negotiation(self, user_id_type, primary_field,
primary_field : bytes
The value of the Primary Field
secondary_field : bytes or None
The value of the Secondary Field. Only used when `user_id_type` is 2
The value of the Secondary Field. Will be None unless the
`user_id_type` is 2
Returns
-------
Expand Down Expand Up @@ -1216,7 +1201,7 @@ def on_association_rejected(self, primitive):
"""
pass

def on_association_released(self):
def on_association_released(self, primitive=None):
"""Callback for when an association is released."""
pass

Expand Down
16 changes: 8 additions & 8 deletions pynetdicom3/association.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,14 +391,14 @@ def _run_as_acceptor(self):
# presentation contexts?
assoc_ac = self.acse.Accept(assoc_rq)

# Callbacks/Logging
self.debug_association_accepted(assoc_ac)
self.ae.on_association_accepted(assoc_ac)

if assoc_ac is None:
self.kill()
return

# Callbacks/Logging
self.debug_association_accepted(assoc_ac)
self.ae.on_association_accepted(assoc_ac)

# No valid presentation contexts, abort the association
if self.acse.presentation_contexts_accepted == []:
self.acse.Abort(0x02, 0x00)
Expand Down Expand Up @@ -437,22 +437,22 @@ def _run_as_acceptor_loop(self):

# DIMSE message received
if msg:
# Use the Message's Affected SOP Class UID to create a new
# Use the Message's Affected SOP Class UID to create a new
# SOP Class instance
sop_class = uid_to_sop_class(msg.AffectedSOPClassUID)()

# Check that the SOP Class is supported by the AE
# New method
pc_accepted = self.acse.presentation_contexts_accepted
context = [pc for pc in pc_accepted if pc.ID == msg_context_id]

# Matching context
if context:
sop_class.presentation_context = context[0]
else:
else:
# No matching presentation context
pass

# Old method
matching_context = False
for context in self.acse.presentation_contexts_accepted:
Expand Down
2 changes: 1 addition & 1 deletion pynetdicom3/fsm.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def do_action(self, event):
event, self.current_state)
raise KeyError("DUL State Machine received an invalid event "
"'{}' for the current state '{}'"
%(event, self.current_state))
.format(event, self.current_state))

action_name = TRANSITION_TABLE[(event, self.current_state)]

Expand Down
Loading

0 comments on commit 0561a36

Please sign in to comment.