Skip to content

Commit

Permalink
Release 1.3.1
Browse files Browse the repository at this point in the history
Fix Issue #3, silent error when put() fails
Add test_permissions to catch this error in the future
Update process_messages.py with the code that was added directly to exceptions.py
  • Loading branch information
WhoBrokeTheBuild committed Sep 5, 2024
1 parent a1a04ea commit dd3918b
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 7 deletions.
2 changes: 1 addition & 1 deletion mdsthin/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ def put(self, path, expr, *args):
"""
args = [path, expr] + list(args)
args_format = ','.join('$' * len(args))
status = self.get(f'TreePut({args_format})', *args)
status = self.get(f'TreePut({args_format})', *args).data()

if STATUS_NOT_OK(status):
raise getException(status)
Expand Down
34 changes: 30 additions & 4 deletions mdsthin/test/write_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ def setUpClass(cls):

# Attempt to find the mdsip executable
mdsip = shutil.which('mdsip')

if mdsip is None:
cls.ENABLED = False

Expand Down Expand Up @@ -94,10 +93,9 @@ def setUpClass(cls):
cls.conn.tcl("add node sig /usage=signal")
cls.conn.tcl("write")
cls.conn.tcl("close")
cls.conn.tcl("set tree thintest /shot=-1")
cls.conn.tcl("create pulse 1") # The readonly tree

# Open a normal connection for the tests to use
cls.conn.openTree('thintest', -1)

super().setUpClass()

@classmethod
Expand All @@ -116,6 +114,9 @@ def tearDownClass(cls):
os.path.join(cls.tempdir, 'thintest_model.tree'),
os.path.join(cls.tempdir, 'thintest_model.datafile'),
os.path.join(cls.tempdir, 'thintest_model.characteristics'),
os.path.join(cls.tempdir, 'thintest_001.tree'),
os.path.join(cls.tempdir, 'thintest_001.datafile'),
os.path.join(cls.tempdir, 'thintest_001.characteristics'),
]

for file in files:
Expand All @@ -132,6 +133,9 @@ def tearDownClass(cls):
def setUp(self):
if not self.ENABLED:
raise unittest.SkipTest('--write was not specified or it was unable to find mdsip executable')

# Open a tree for the tests to use
self.conn.openTree('thintest', -1)

def test_numeric(self):

Expand Down Expand Up @@ -227,3 +231,25 @@ def test_putmany(self):
self.assertEqual(self.conn.get('num'), Int32(42))
self.assertEqual(self.conn.get('str'), String("Hello, World!"))
self.assertEqual(self.conn.getObject('nusigm'), Signal(1, 2, 3))

def test_permissions(self):
import platform

if platform.system() == 'Windows':
raise unittest.SkipTest('Disabled on Windows')

# Change all the readonly tree files to be readonly
filenames = [
os.path.join(self.tempdir, 'thintest_001.tree'),
os.path.join(self.tempdir, 'thintest_001.datafile'),
os.path.join(self.tempdir, 'thintest_001.characteristics'),
]
for filename in filenames:
os.chmod(filename, 0o400)

# Open the readonly tree
self.conn.openTree('thintest', 1)

self.assertRaises(TreeFAILURE, self.conn.put, 'num', '42')

self.conn.closeTree('thintest', 1)
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[project]
name = "mdsthin"
description = "MDSplus Thin-Client implemented in pure python"
version = "1.3.0"
version = "1.3.1"
license = {file = "LICENSE"}
readme = "README.md"
authors = [
Expand Down
5 changes: 4 additions & 1 deletion scripts/process_messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,10 @@ def getException(status):
return EXCEPTION_MAP.get(status, MdsException(f'Unknown status: {status}'))
def getExceptionFromError(error):
if type(error) is str and error.startswith('%'):
if error is None:
return None
if error.startswith('%'):
prefix = error.split(',', maxsplit=1)[0]
return EXCEPTION_PREFIX_MAP.get(prefix, MdsException(error))
Expand Down

0 comments on commit dd3918b

Please sign in to comment.