Skip to content

Commit 2188e67

Browse files
committed
Added basic tests for VivaTPS
1 parent d7a3dc0 commit 2188e67

File tree

3 files changed

+39
-5
lines changed

3 files changed

+39
-5
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,6 @@ source = "vcs"
3939
version-file = "src/geocompy/_version.py"
4040

4141
[tool.pytest.ini_options]
42-
addopts = ["-ra"]
42+
addopts = ["-ra", "-v"]
4343
testpaths = ["tests", "src", "examples"]
4444
required_plugins = "pytest-mock"

src/geocompy/vivatps/__init__.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -180,10 +180,13 @@ def __init__(
180180
"""Theodolite measurement and calculation subsystem."""
181181

182182
for i in range(retry):
183-
self._conn.send("\n")
184-
response = self.com.nullproc()
185-
if response.comcode and response.rpccode:
186-
break
183+
try:
184+
self._conn.send("\n")
185+
response = self.com.nullproc()
186+
if response.comcode and response.rpccode:
187+
break
188+
except Exception:
189+
pass
187190

188191
sleep(1)
189192
else:

tests/test_vivatps.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import pytest
2+
3+
from geocompy.communication import Connection
4+
from geocompy.vivatps import VivaTPS
5+
6+
from helpers_geocom import (
7+
DummyGeoComConnection,
8+
GeoComTester
9+
)
10+
11+
12+
@pytest.fixture
13+
def tps() -> VivaTPS:
14+
return VivaTPS(DummyGeoComConnection())
15+
16+
17+
class TestVivaTPS:
18+
def test_init(self):
19+
conn_bad = Connection()
20+
with pytest.raises(ConnectionError):
21+
VivaTPS(conn_bad, retry=1)
22+
23+
conn_good = DummyGeoComConnection()
24+
instrument = VivaTPS(conn_good)
25+
assert instrument._precision == 15
26+
27+
def test_parse_response(self, tps: VivaTPS):
28+
GeoComTester.test_parse_response(tps)
29+
30+
def test_request(self, tps: VivaTPS):
31+
GeoComTester.test_request(tps)

0 commit comments

Comments
 (0)