Skip to content

Commit

Permalink
Update 'no_output' to 'no_reply' in received_data.py
Browse files Browse the repository at this point in the history
  • Loading branch information
sisoe24 committed Dec 25, 2023
1 parent 7779850 commit 0966ea7
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion nukeserversocket/editor_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def run(self, data: ReceivedData) -> str:

if (
not self.settings.get('mirror_script_editor') or
data.no_output
data.no_reply
):
LOGGER.debug('Restoring script editor.')
self.input_editor.setPlainText(initial_input)
Expand Down
10 changes: 5 additions & 5 deletions nukeserversocket/received_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class ReceivedData:
{
"text": "Text to run in the script editor",
"file": "File name to show in the output (optional))"
"no_output": "0" or "1" To disable output in the script editor (optional)"
"noReply": "0" or "1" To disable output in the script editor (optional)"
}
Raises:
Expand All @@ -31,17 +31,17 @@ class ReceivedData:
data: Dict[str, str] = field(init=False)
file: str = field(init=False)
text: str = field(init=False)
no_output: bool = field(init=False)
no_reply: bool = field(init=False)

def __post_init__(self):

try:
self.data = json.loads(self.raw)
self.data.setdefault('file', '')
self.data.setdefault('no_output', '0')
self.data.setdefault('noReply', '0')
except Exception as e:
LOGGER.error(f'An exception occurred while decoding the data. {e}')
self.data = {'text': '', 'file': '', 'no_output': '0'}
self.data = {'text': '', 'file': '', 'noReply': '0'}

LOGGER.debug('Received data: %s', self.data)

Expand All @@ -50,4 +50,4 @@ def __post_init__(self):
LOGGER.critical('Data does not contain a text field.')

self.file = self.data['file']
self.no_output = bool(int(self.data['no_output']))
self.no_reply = bool(int(self.data['noReply']))
18 changes: 9 additions & 9 deletions tests/test_received_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,41 +14,41 @@ class ReceivedTestData:
data: Dict[str, str]
text: str
file: str
no_output: bool = False
no_reply: bool = False


@pytest.mark.parametrize('data', [
ReceivedTestData(
'{"text": "Hello World", "file": "test.py", "no_output": "1"}',
{'text': 'Hello World', 'file': 'test.py', 'no_output': '1'},
'{"text": "Hello World", "file": "test.py", "noReply": "1"}',
{'text': 'Hello World', 'file': 'test.py', 'noReply': '1'},
'Hello World',
'test.py',
True
),
ReceivedTestData(
'{"text": "Hello World", "file": "test.py", "no_output": "0"}',
{'text': 'Hello World', 'file': 'test.py', 'no_output': '0'},
'{"text": "Hello World", "file": "test.py", "noReply": "0"}',
{'text': 'Hello World', 'file': 'test.py', 'noReply': '0'},
'Hello World',
'test.py',
False
),
ReceivedTestData(
'{"text": "Hello World", "file": ""}',
{'text': 'Hello World', 'file': '', 'no_output': '0'},
{'text': 'Hello World', 'file': '', 'noReply': '0'},
'Hello World',
'',
False
),
ReceivedTestData(
'{"text": "Hello World"}',
{'text': 'Hello World', 'file': '', 'no_output': '0'},
{'text': 'Hello World', 'file': '', 'noReply': '0'},
'Hello World',
'',
False
),
ReceivedTestData(
'{"text": "",',
{'text': '', 'file': '', 'no_output': '0'},
{'text': '', 'file': '', 'noReply': '0'},
'',
'',
False
Expand All @@ -62,4 +62,4 @@ def test_received_data(data: ReceivedTestData):
assert received.data == data.data
assert received.text == data.text
assert received.file == data.file
assert received.no_output == data.no_output
assert received.no_reply == data.no_reply

0 comments on commit 0966ea7

Please sign in to comment.