update several drivers

This commit is contained in:
Nico Melone
2025-03-13 16:01:03 -05:00
parent 0b8787d7b9
commit fb7667ff1a
16 changed files with 177625 additions and 507 deletions

View File

@@ -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

View 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()