update several drivers
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 1,
|
||||
"execution_count": 2,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
@@ -12,7 +12,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 2,
|
||||
"execution_count": 3,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
@@ -389,7 +389,7 @@
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "tbDataCollector",
|
||||
"display_name": "pycomm",
|
||||
"language": "python",
|
||||
"name": "python3"
|
||||
},
|
||||
@@ -403,7 +403,7 @@
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.10.5"
|
||||
"version": "3.13.2"
|
||||
},
|
||||
"orig_nbformat": 4
|
||||
},
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
47
code snippets/test_plctags.py
Normal file
47
code snippets/test_plctags.py
Normal file
@@ -0,0 +1,47 @@
|
||||
import unittest
|
||||
from unittest.mock import MagicMock
|
||||
from getPLCData import LogixDriver # assume this is the name of the file containing the LogixDriver class
|
||||
|
||||
class TestGetPLCTags(unittest.TestCase):
|
||||
|
||||
def test_get_plc_tags(self):
|
||||
# Mock out the LogixDriver connection to a PLC
|
||||
ip_address = "192.168.1.100"
|
||||
plc = MagicMock(spec=LogixDriver)
|
||||
|
||||
# Simulate getting the tag list from the PLC
|
||||
plc.get_tag_list.return_value = ["tag1", "tag2", "tag3"]
|
||||
|
||||
with LogixDriver(ip_address) as plc:
|
||||
tags_json = plc.tags_json
|
||||
|
||||
self.assertEqual(tags_json, {"tags": ["tag1", "tag2", "tag3"]})
|
||||
|
||||
def test_get_plc_tags_fail(self):
|
||||
# Mock out the LogixDriver connection to a PLC
|
||||
ip_address = "192.168.1.100"
|
||||
plc = MagicMock(spec=LogixDriver)
|
||||
|
||||
# Simulate getting an error when trying to connect to the PLC
|
||||
with self.assertRaises(Exception):
|
||||
with LogixDriver(ip_address) as plc:
|
||||
plctags = plc.get_tag_list()
|
||||
|
||||
def test_write_tags_to_file(self):
|
||||
# Mock out the file I/O operations
|
||||
with unittest.mock.patch('builtins.open', create=True, spec='open'):
|
||||
with unittest.mock.patch('json.dump') as mock_dump:
|
||||
|
||||
ip_address = "192.168.1.100"
|
||||
plc = MagicMock(spec=LogixDriver)
|
||||
|
||||
# Simulate getting the tag list from the PLC
|
||||
plc.get_tag_list.return_value = ["tag1", "tag2", "tag3"]
|
||||
|
||||
with LogixDriver(ip_address) as plc:
|
||||
plctags = plc.tags_json
|
||||
|
||||
mock_dump.assert_called_once_with(plctags, unittest.mock.ANY, indent=4)
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user