Skip to content

Commit

Permalink
make tests work with itnc and cncpilot
Browse files Browse the repository at this point in the history
  • Loading branch information
drunsinn committed Apr 26, 2021
1 parent 4742e0a commit c0e643e
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 47 deletions.
101 changes: 65 additions & 36 deletions tests/test_file_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,17 @@ def test_read_info(address, timeout):
"""test if reading of file information works"""
lsv2 = pyLSV2.LSV2(address, port=19000, timeout=timeout, safe_mode=True)
lsv2.connect()

if lsv2.is_itnc():
mdi_path = 'TNC:/$MDI.H'
elif lsv2.is_pilot():
mdi_path = 'TNC:/nc_prog/ncps/PGM01.nc'
else:
mdi_path = 'TNC:/nc_prog/$mdi.h'

assert lsv2.change_directory(remote_directory='TNC:/nc_prog') is True
assert lsv2.get_directory_info() is not False
assert lsv2.get_file_info(remote_file_path='TNC:/nc_prog/$mdi.h') is not False
assert lsv2.get_file_info(remote_file_path=mdi_path) is not False
assert lsv2.get_directory_content() is not False
assert lsv2.get_drive_info() is not False
lsv2.disconnect()
Expand All @@ -20,58 +28,79 @@ def test_read_info(address, timeout):
def test_directory_functions(address, timeout):
"""test if functions to change, create and delete directories work"""
lsv2 = pyLSV2.LSV2(address, port=19000, timeout=timeout, safe_mode=True)

test_dir = 'TNC:/nc_prog/pyLSV2_test/'

lsv2.connect()
assert lsv2.change_directory('TNC:/nc_prog') is True
assert lsv2.make_directory('TNC:/nc_prog/pyLSV2_test/T1/T2/T3') is True
assert lsv2.delete_empty_directory(
'TNC:/nc_prog/pyLSV2_test/T1/T2/T3') is True
assert lsv2.change_directory('TNC:/nc_prog/pyLSV2_test/T1/T2/T3') is False
assert lsv2.change_directory('TNC:/nc_prog/pyLSV2_test/T1/T2') is True
assert lsv2.delete_empty_directory(
'TNC:/nc_prog/pyLSV2_test/T1/T2') is False
assert lsv2.change_directory('TNC:/nc_prog') is True
assert lsv2.delete_empty_directory(
'TNC:/nc_prog/pyLSV2_test/T1/T2') is True
assert lsv2.delete_empty_directory('TNC:/nc_prog/pyLSV2_test/T1') is True
assert lsv2.delete_empty_directory('TNC:/nc_prog/pyLSV2_test') is True
assert lsv2.make_directory(test_dir + 'T1/T2/T3') is True
assert lsv2.delete_empty_directory(test_dir + 'T1/T2/T3') is True
assert lsv2.change_directory(test_dir + 'T1/T2/T3') is False
assert lsv2.change_directory(test_dir + 'T1/T2') is True

if lsv2.is_itnc():
assert lsv2.delete_empty_directory(test_dir + 'T1/T2') is True
assert lsv2.change_directory('TNC:/nc_prog') is True
else:
assert lsv2.delete_empty_directory(test_dir + 'T1/T2') is False
assert lsv2.change_directory('TNC:/nc_prog') is True
assert lsv2.delete_empty_directory(test_dir + 'T1/T2') is True

assert lsv2.delete_empty_directory(test_dir + 'T1') is True
assert lsv2.delete_empty_directory(test_dir) is True
lsv2.disconnect()


def test_remote_file_functions(address, timeout):
"""test if functions for manipulating the remote file system work"""
lsv2 = pyLSV2.LSV2(address, port=19000, timeout=timeout, safe_mode=True)
lsv2.connect()
assert lsv2.make_directory('TNC:/nc_prog/pyLSV2_test') is True
assert lsv2.change_directory('TNC:/nc_prog/pyLSV2_test') is True

assert lsv2.copy_local_file(
source_path='TNC:/nc_prog/$mdi.h', target_path='TNC:/nc_prog/pyLSV2_test/') is True
assert lsv2.get_file_info('TNC:/nc_prog/pyLSV2_test/$mdi.h') is not False
test_dir = 'TNC:/nc_prog/pyLSV2_test/'

assert lsv2.copy_local_file(
source_path='TNC:/nc_prog/$mdi.h', target_path='TNC:/nc_prog/pyLSV2_test/aa.h') is True
assert lsv2.get_file_info('TNC:/nc_prog/pyLSV2_test/aa.h') is not False
if lsv2.is_itnc():
mdi_dir = 'TNC:/'
mdi_name = '$MDI.H'
elif lsv2.is_pilot():
mdi_dir = 'TNC:/nc_prog/ncps/'
mdi_name = 'PGM01.nc'
else:
mdi_dir = 'TNC:/nc_prog/'
mdi_name = '$mdi.h'

test_file_1 = test_dir + 'aa.h'
test_file_2 = test_dir + 'bb.h'
test_file_3 = test_dir + 'cc.h'

assert lsv2.make_directory(test_dir) is True
assert lsv2.change_directory(test_dir) is True

if lsv2.is_tnc():
#only test for tnc controls
assert lsv2.copy_local_file(
source_path=mdi_dir + mdi_name, target_path=test_dir) is True
assert lsv2.get_file_info(test_dir + mdi_name) is not False
assert lsv2.delete_file(test_dir + mdi_name) is True

assert lsv2.copy_local_file(
source_path='TNC:/nc_prog/$mdi.h', target_path='mdi.b') is True
assert lsv2.get_file_info('TNC:/nc_prog/mdi.b') is not False
source_path=mdi_dir + mdi_name, target_path=test_file_1) is True
assert lsv2.get_file_info(test_file_1) is not False

assert lsv2.change_directory(remote_directory='TNC:/nc_prog') is True
assert lsv2.change_directory(remote_directory=mdi_dir) is True
assert lsv2.copy_local_file(
source_path='$mdi.h', target_path='TNC:/nc_prog/pyLSV2_test/bb.h') is True
assert lsv2.get_file_info('TNC:/nc_prog/pyLSV2_test/bb.h') is not False
source_path=mdi_name, target_path=test_file_2) is True

assert lsv2.move_local_file(source_path='TNC:/nc_prog/pyLSV2_test/bb.h',
target_path='TNC:/nc_prog/pyLSV2_test/cc.h') is True
assert lsv2.get_file_info('TNC:/nc_prog/pyLSV2_test/cc.h') is not False
assert lsv2.get_file_info(test_file_2) is not False

assert lsv2.delete_file('TNC:/nc_prog/pyLSV2_test/cc.h') is True
assert lsv2.get_file_info('TNC:/nc_prog/pyLSV2_test/cc.h') is False
assert lsv2.move_local_file(source_path=test_file_2,
target_path=test_file_3) is True
assert lsv2.get_file_info(test_file_3) is not False

assert lsv2.delete_file('TNC:/nc_prog/pyLSV2_test/aa.h') is True
assert lsv2.delete_file('TNC:/nc_prog/pyLSV2_test/$mdi.h') is True
assert lsv2.delete_file('TNC:/nc_prog/mdi.b') is True
assert lsv2.delete_file(test_file_3) is True
assert lsv2.get_file_info(test_file_3) is False

assert lsv2.change_directory('TNC:/nc_prog') is True
assert lsv2.delete_empty_directory('TNC:/nc_prog/pyLSV2_test') is True
assert lsv2.delete_file(test_file_1) is True

assert lsv2.change_directory(mdi_dir) is True
assert lsv2.delete_empty_directory(test_dir) is True
lsv2.disconnect()
18 changes: 9 additions & 9 deletions tests/test_machine_parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,26 @@ def test_read_machine_parameter(address, timeout):
lsv2 = pyLSV2.LSV2(address, port=19000, timeout=timeout, safe_mode=False)
lsv2.connect()

if lsv2.get_versions()['Control'] in ('TNC640', 'TNC620', 'TNC320', 'TNC128'):
if lsv2.is_itnc():
# old style
assert lsv2.get_machine_parameter('7230.0') is not False
else:
# new stype
assert lsv2.get_machine_parameter('CfgDisplayLanguage.ncLanguage') is not False
else:
# old style
assert lsv2.get_machine_parameter('7320.0') is not False


lsv2.disconnect()

def test_rw_machine_parameter(address, timeout):
"""test to see if reading and writing of machine parameters works"""
lsv2 = pyLSV2.LSV2(address, port=19000, timeout=timeout, safe_mode=False)
lsv2.connect()

if lsv2.get_versions()['Control'] in ('TNC640', 'TNC620', 'TNC320', 'TNC128'):
if lsv2.is_itnc():
# old style
parameter_name = '7230.0'
else:
# new stype
parameter_name = 'CfgDisplayLanguage.ncLanguage'
else:
# old style
parameter_name = '7320.0'

lsv2.login(pyLSV2.LOGIN_PLCDEBUG)
current_value = lsv2.get_machine_parameter(parameter_name)
Expand Down
14 changes: 12 additions & 2 deletions tests/test_transfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,25 @@ def test_file_recive(address, timeout):
lsv2 = pyLSV2.LSV2(address, port=19000, timeout=timeout, safe_mode=True)
lsv2.connect()

if lsv2.is_itnc():
mdi_path = 'TNC:/$MDI.H'
tool_t_path = 'TNC:/TOOL.T'
elif lsv2.is_pilot():
mdi_path = 'TNC:/nc_prog/ncps/PGM01.nc'
tool_t_path = 'TNC:/table/toolturn.htt'
else:
mdi_path = 'TNC:/nc_prog/$mdi.h'
tool_t_path = 'TNC:/table/tool.t'

with tempfile.TemporaryDirectory(suffix=None, prefix='pyLSV2_') as tmp_dir_name:
local_mdi_path = Path(tmp_dir_name).joinpath('mdi.h')
assert lsv2.recive_file(local_path=str(local_mdi_path),
remote_path='TNC:/nc_prog/$mdi.h',
remote_path=mdi_path,
binary_mode=False) is True

local_tool_table_path = Path(tmp_dir_name).joinpath('tool.t')
assert lsv2.recive_file(local_path=str(local_tool_table_path),
remote_path='TNC:/table/tool.t') is True
remote_path=tool_t_path) is True

lsv2.disconnect()

Expand Down

0 comments on commit c0e643e

Please sign in to comment.