Skip to content

Commit

Permalink
Merge pull request #552 from radical-cybertools/feature/name_exception
Browse files Browse the repository at this point in the history
naming warning update to exception
  • Loading branch information
Ioannis Paraskevakos committed Feb 16, 2021
2 parents e266a66 + dc5f047 commit 59ced46
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 31 deletions.
14 changes: 5 additions & 9 deletions src/radical/entk/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
__license__ = 'MIT'

import threading
import warnings

import radical.utils as ru

Expand Down Expand Up @@ -166,11 +165,10 @@ def name(self, value):
actual_type=type(value))

if any(symbol in value for symbol in invalid_symbols):
warnings.warn(NAME_MESSAGE, DeprecationWarning)
# raise ree.ValueError(obj=self._uid,
# attribute='name',
# actual_value=value,
# expected_value=NAME_MESSAGE)
raise ree.ValueError(obj=self._uid,
attribute='name',
actual_value=value,
expected_value=NAME_MESSAGE)

self._name = value

Expand Down Expand Up @@ -266,9 +264,7 @@ def from_dict(self, d):
raise ree.ValueError(obj=self._uid,
attribute='name',
actual_value=d['name'],
expected_value="Valid object names can " +
"contains letters, numbers and '.'. Any "
"other character is not allowed")
expected_value=NAME_MESSAGE)

self._name = d['name']

Expand Down
14 changes: 5 additions & 9 deletions src/radical/entk/stage.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@


import radical.utils as ru
import warnings

from string import punctuation
from . import exceptions as ree
Expand Down Expand Up @@ -175,11 +174,10 @@ def name(self, value):
actual_type=type(value))

if any(symbol in value for symbol in invalid_symbols):
warnings.warn(NAME_MESSAGE, DeprecationWarning)
# raise ree.ValueError(obj=self._uid,
# attribute='name',
# actual_value=value,
# expected_value=NAME_MESSAGE)
raise ree.ValueError(obj=self._uid,
attribute='name',
actual_value=value,
expected_value=NAME_MESSAGE)
self._name = value

@tasks.setter
Expand Down Expand Up @@ -285,9 +283,7 @@ def from_dict(self, d):
raise ree.ValueError(obj=self._uid,
attribute='name',
actual_value=d['name'],
expected_value="Valid object names can " +
"contains letters, numbers and '.'. Any "
"other character is not allowed")
expected_value=NAME_MESSAGE)
self._name = d['name']

if 'state' in d:
Expand Down
43 changes: 31 additions & 12 deletions src/radical/entk/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
from . import exceptions as ree
from . import states as res

warnings.simplefilter(action="once", category=DeprecationWarning, lineno=724)
warnings.simplefilter(action="once", category=DeprecationWarning, lineno=782)
warnings.simplefilter(action="once", category=DeprecationWarning, lineno=950)
warnings.simplefilter(action="once", category=DeprecationWarning, lineno=728)
warnings.simplefilter(action="once", category=DeprecationWarning, lineno=786)
warnings.simplefilter(action="once", category=DeprecationWarning, lineno=954)


# ------------------------------------------------------------------------------
Expand Down Expand Up @@ -592,11 +592,16 @@ def rts_uid(self):
#
@uid.setter
def uid(self, value):

invalid_symbols = punctuation.replace('.','')
if not isinstance(value, str):
raise ree.TypeError(expected_type=str,
actual_type=type(value))

if any(symbol in value for symbol in invalid_symbols):
raise ree.ValueError(obj=self._uid,
attribute='uid',
actual_value=value,
expected_value=NAME_MESSAGE)
self._uid = value

@rts_uid.setter
Expand All @@ -616,11 +621,10 @@ def name(self, value):
actual_type=type(value))

if any(symbol in value for symbol in invalid_symbols):
warnings.warn(NAME_MESSAGE, DeprecationWarning, stacklevel=2)
# raise ree.ValueError(obj=self._uid,
# attribute='name',
# actual_value=value,
# expected_value=NAME_MESSAGE)
raise ree.ValueError(obj=self._uid,
attribute='name',
actual_value=value,
expected_value=NAME_MESSAGE)

self._name = value

Expand Down Expand Up @@ -1051,13 +1055,28 @@ def from_dict(self, d):
:return: None
'''

invalid_symbols = punctuation.replace('.','')
# FIXME: uid, name, state and state_history to use setter type checks
if d.get('uid') is not None: self._uid = d['uid']
if d.get('name') is not None: self._name = d['name']
if d.get('uid') is not None:
if any(symbol in d['uid'] for symbol in invalid_symbols):
raise ree.ValueError(obj=self._uid,
attribute='uid',
actual_value=d['uid'],
expected_value=NAME_MESSAGE)
else:
self._uid = d['uid']

if d.get('name') is not None:
if any(symbol in d['name'] for symbol in invalid_symbols):
raise ree.ValueError(obj=self._uid,
attribute='name',
actual_value=d['name'],
expected_value=NAME_MESSAGE)
else:
self._name = d['name']

if 'state' not in d:
self._state = res.INITIAL

else:
# avoid adding state to state history, thus do typecheck here
if not isinstance(d['state'], str):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_component/test_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ def test_name(self, mocked_init):
with self.assertRaises(ree.TypeError):
task.name = 0

with self.assertWarns(DeprecationWarning):
with self.assertRaises(ree.ValueError):
task.name = 'task,0000'


Expand Down

0 comments on commit 59ced46

Please sign in to comment.