Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

try to fix more builds #502

Merged
merged 5 commits into from
May 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/actions/prepare_snap7/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ runs:
steps:
- name: Cache snap7-archive
id: snap7-archive
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: snap7-full-1.4.2.7z
key: ${{ inputs.snap7-archive-url }}
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/build-and-test-arm64.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ jobs:
-v $PWD/pyproject.toml:/pyproject.toml \
-v $PWD/wheelhouse:/wheelhouse \
"arm64v8/python:${{ matrix.python-version }}-bookworm" /bin/bash -s <<EOF
python3 -m pip install --upgrade pip
python3 -m pip install $(ls wheelhouse/*_aarch64.whl)
python3 -m pip install pytest
python -m pytest tests/ -m "server or util or client or mainloop or partner"
python3 -m pytest tests/test_client.py tests/test_mainloop.py tests/test_server.py tests/test_util.py
EOF
10 changes: 8 additions & 2 deletions .github/workflows/doc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,17 @@ jobs:
run: |
sudo apt-get update -qq
sudo apt-get install -y python3-pip make
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: 3.9
- name: Install dependencies
run: |
sudo python3 -m pip install --upgrade pip
sudo python3 -m pip install .[doc]
python3 -m venv venv
venv/bin/pip install --upgrade pip
venv/bin/pip install ".[doc,cli]"
- name: Run doc
run: |
source venv/bin/activate
cd doc
make html
10 changes: 5 additions & 5 deletions .github/workflows/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ jobs:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python3 -m pip install --upgrade pip
python3 -m pip install .[test]
python3 -m venv venv
venv/bin/pip install --upgrade pip
venv/bin/pip install ".[test]"
- name: Run pytest
run: |
which pytest
pytest -m "server or util or client or mainloop"
sudo /opt/hostedtoolcache/Python/${{ matrix.python-version }}*/x64/bin/pytest -m partner
venv/bin/pytest tests/test_client.py tests/test_mainloop.py tests/test_server.py tests/test_util.py
sudo venv/bin/pytest tests/test_partner.py
2 changes: 2 additions & 0 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ jobs:
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.8'
- uses: pre-commit/action@v3.0.1
7 changes: 5 additions & 2 deletions snap7/util/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@

from snap7.client import Client
from snap7.types import Areas
from snap7.util import (
parse_specification,

from snap7.util import parse_specification
from snap7.util.getters import (
get_bool,
get_fstring,
get_string,
Expand All @@ -31,6 +32,8 @@
get_char,
get_wchar,
get_dtl,
)
from snap7.util.setters import (
set_bool,
set_fstring,
set_string,
Expand Down
3 changes: 0 additions & 3 deletions tests/bla.py

This file was deleted.

47 changes: 24 additions & 23 deletions tests/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,18 @@
import unittest
from unittest import mock

import snap7.error
import snap7.server
import snap7.types
from snap7.common import error_text
from snap7.error import server_errors
from snap7.server import Server
from snap7.types import SrvEvent, mkEvent, mkLog, srvAreaDB, LocalPort, WorkInterval, MaxClients, RemotePort

logging.basicConfig(level=logging.WARNING)


@pytest.mark.server
class TestServer(unittest.TestCase):
def setUp(self):
self.server = snap7.server.Server()
self.server = Server()
self.server.start(tcpport=1102)

def tearDown(self):
Expand All @@ -23,29 +24,29 @@ def tearDown(self):

def test_register_area(self):
db1_type = ctypes.c_char * 1024
self.server.register_area(snap7.types.srvAreaDB, 3, db1_type())
self.server.register_area(srvAreaDB, 3, db1_type())

def test_error(self):
for error in snap7.error.server_errors:
snap7.common.error_text(error, context="client")
for error in server_errors:
error_text(error, context="client")

def test_event(self):
event = snap7.types.SrvEvent()
event = SrvEvent()
self.server.event_text(event)

def test_get_status(self):
server, cpu, num_clients = self.server.get_status()

def test_get_mask(self):
self.server.get_mask(snap7.types.mkEvent)
self.server.get_mask(snap7.types.mkLog)
self.server.get_mask(mkEvent)
self.server.get_mask(mkLog)
# invalid kind
self.assertRaises(Exception, self.server.get_mask, 3)

def test_lock_area(self):
from threading import Thread

area_code = snap7.types.srvAreaDB
area_code = srvAreaDB
index = 1
db1_type = ctypes.c_char * 1024
# we need to register first
Expand All @@ -72,10 +73,10 @@ def test_set_cpu_status(self):
self.assertRaises(ValueError, self.server.set_cpu_status, -1)

def test_set_mask(self):
self.server.set_mask(kind=snap7.types.mkEvent, mask=10)
self.server.set_mask(kind=mkEvent, mask=10)

def test_unlock_area(self):
area_code = snap7.types.srvAreaDB
area_code = srvAreaDB
index = 1
db1_type = ctypes.c_char * 1024

Expand All @@ -87,7 +88,7 @@ def test_unlock_area(self):
self.server.unlock_area(area_code, index)

def test_unregister_area(self):
area_code = snap7.types.srvAreaDB
area_code = srvAreaDB
index = 1
db1_type = ctypes.c_char * 1024
self.server.register_area(area_code, index, db1_type())
Expand All @@ -107,7 +108,7 @@ def read_events_call_back(event):

def test_pick_event(self):
event = self.server.pick_event()
self.assertEqual(type(event), snap7.types.SrvEvent)
self.assertEqual(type(event), SrvEvent)
event = self.server.pick_event()
self.assertFalse(event)

Expand All @@ -121,12 +122,12 @@ def test_start_to(self):

def test_get_param(self):
# check the defaults
self.assertEqual(self.server.get_param(snap7.types.LocalPort), 1102)
self.assertEqual(self.server.get_param(snap7.types.WorkInterval), 100)
self.assertEqual(self.server.get_param(snap7.types.MaxClients), 1024)
self.assertEqual(self.server.get_param(LocalPort), 1102)
self.assertEqual(self.server.get_param(WorkInterval), 100)
self.assertEqual(self.server.get_param(MaxClients), 1024)

# invalid param for server
self.assertRaises(Exception, self.server.get_param, snap7.types.RemotePort)
self.assertRaises(Exception, self.server.get_param, RemotePort)


@pytest.mark.server
Expand All @@ -136,10 +137,10 @@ class TestServerBeforeStart(unittest.TestCase):
"""

def setUp(self):
self.server = snap7.server.Server()
self.server = Server()

def test_set_param(self):
self.server.set_param(snap7.types.LocalPort, 1102)
self.server.set_param(LocalPort, 1102)


@pytest.mark.server
Expand All @@ -161,11 +162,11 @@ def tearDown(self):
self.loadlib_patch.stop()

def test_create(self):
snap7.server.Server(log=False)
Server(log=False)
self.mocklib.Srv_Create.assert_called_once()

def test_gc(self):
server = snap7.server.Server(log=False)
server = Server(log=False)
del server
self.mocklib.Srv_Destroy.assert_called_once()

Expand Down
Loading
Loading