Skip to content

Commit 7c5cf77

Browse files
author
iPhysicX
committed
fix tests
1 parent 8869a50 commit 7c5cf77

9 files changed

+282
-21
lines changed

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ install:
77
install-dev:
88
pip install -r requirements_dev.txt
99

10+
test-sim:
11+
python example.py
12+
1013
test: install install-dev
1114
python -m pytest --cov=SimConnect --cov-report xml
1215

Pipfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ pytest-cov = "*"
99
[packages]
1010

1111
[requires]
12-
python_version = "3.6"
12+
python_version = "3.8"

Pipfile.lock

Lines changed: 163 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

example.py

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
from SimConnect import *
2+
3+
from unittest import TestCase
4+
5+
import logging
6+
logging.basicConfig(level=logging.DEBUG)
7+
LOGGER = logging.getLogger(__name__)
8+
9+
LOGGER.info("START")
10+
# creat simconnection and pass used user classes
11+
sm = SimConnect()
12+
13+
# creat Request
14+
myRequest = sm.newRequest(time=2000) # set auto data collection time @ 2s
15+
# add instreaded definitions output data name, definition form SDK
16+
myRequest.add('Altitude', (b'Plane Altitude', b'feet'))
17+
myRequest.add('Latitude', (b'Plane Latitude', b'degrees'))
18+
myRequest.add('Longitude', (b'Plane Longitude', b'degrees'))
19+
myRequest.add('Kohlsman', (b'Kohlsman setting hg', b'inHg'))
20+
21+
# creat Request
22+
myRequest2 = sm.newRequest()
23+
# add instreaded definitions output data name, definition form SDK
24+
myRequest2.add('ALTITUDE', (b'PRESSURE ALTITUDE', b'feet'))
25+
myRequest2.add('GEAR', (b'GEAR HANDLE POSITION', b'bool'))
26+
# Add data request Definition
27+
28+
29+
# creat Request
30+
AUTOPILOTRequest = sm.newRequest(time=5000) # set auto data collection time @ 5s
31+
# add instreaded definitions output data name, definition form SDK
32+
AUTOPILOTRequest.add('AUTOPILOT_MASTER', (b'AUTOPILOT MASTER', b'Bool'))
33+
34+
35+
# add input events
36+
GEAR_DOWN = sm.MapToSimEvent(b'GEAR_DOWN')
37+
GEAR_UP = sm.MapToSimEvent(b'GEAR_UP')
38+
GEAR_TOGGLE = sm.MapToSimEvent(b'GEAR_TOGGLE')
39+
AP_MASTER = sm.MapToSimEvent(b'AP_MASTER')
40+
41+
42+
# time holder for inline commands
43+
ct_r2 = millis()
44+
ct_g = millis()
45+
46+
while not sm.quit:
47+
# send request for new data inine @ 10s
48+
if (ct_r2 + 10000) < millis():
49+
sm.RequestData(myRequest2)
50+
ct_r2 = millis()
51+
52+
# send request for new data inine @ 15s
53+
if ct_g + 15000 < millis():
54+
LOGGER.info("TOGGLE GEAR")
55+
sm.SendData(GEAR_TOGGLE)
56+
ct_g = millis()
57+
58+
# updated system
59+
sm.Run()
60+
61+
# check for data from myRequest
62+
data = sm.GetData(myRequest)
63+
if data is not None:
64+
LOGGER.info("Lat=%f Lon=%f Alt=%f Kohlsman=%.2f" % (
65+
data.Latitude,
66+
data.Longitude,
67+
data.Altitude,
68+
data.Kohlsman
69+
))
70+
71+
# check for data from myRequest2
72+
data = sm.GetData(myRequest2)
73+
if data is not None:
74+
LOGGER.info("Alt=%f GEAR=%d" % (
75+
data.ALTITUDE,
76+
data.GEAR
77+
))
78+
79+
# check for data from AUTOPILOTRequest
80+
data = sm.GetData(AUTOPILOTRequest)
81+
if data is not None:
82+
LOGGER.info("AUTOPILOT_MASTER: %d" % (
83+
data.AUTOPILOT_MASTER
84+
))
85+
86+
sm.Exit()

requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
-i https://pypi.org/simple
2+

requirements_dev.txt

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
1-
attrs==19.3.0
2-
coverage==5.2
3-
importlib-metadata==1.7.0; python_version < '3.8'
4-
more-itertools==8.4.0
5-
packaging==20.4
6-
pluggy==0.13.1
7-
py==1.9.0
8-
pyparsing==2.4.7
9-
pytest-cov==2.10.0
10-
pytest==5.4.3
11-
six==1.15.0
12-
wcwidth==0.2.5
13-
zipp==3.1.0
1+
-i https://pypi.org/simple
2+
atomicwrites==1.4.0; sys_platform == 'win32'
3+
attrs==20.1.0; python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'
4+
colorama==0.4.3; sys_platform == 'win32'
5+
coverage==5.2.1; python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4' and python_version < '4'
6+
iniconfig==1.0.1
7+
more-itertools==8.5.0; python_version >= '3.5'
8+
packaging==20.4; python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'
9+
pluggy==0.13.1; python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'
10+
py==1.9.0; python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'
11+
pyparsing==2.4.7; python_version >= '2.6' and python_version not in '3.0, 3.1, 3.2'
12+
pytest-cov==2.10.1
13+
pytest==6.0.1; python_version >= '3.5'
14+
six==1.15.0; python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2'
15+
toml==0.10.1

setup.cfg

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ requires = ["setuptools >= 40.6.0", "wheel"]
4242
build-backend = "setuptools.build_meta"
4343

4444
[tool:pytest]
45-
minversion = 5.0
46-
addopts = -ra -q
45+
minversion = 6.0
4746
testpaths =
4847
tests
49-
log_level = DEBUG
48+
log_level = DEBUG
49+
log_cli_level = DEBUG

tests/test_request.py

Whitespace-only changes.

tests/test_first.py renamed to tests/test_simconnect.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,13 @@
22

33
from unittest import TestCase
44

5+
import logging
6+
7+
LOGGER = logging.getLogger(__name__)
8+
59
class TestSimple(TestCase):
610
def test_first_test(self):
11+
LOGGER.info("START")
712
# creat simconnection and pass used user classes
813
sm = SimConnect()
914

@@ -48,7 +53,7 @@ def test_first_test(self):
4853

4954
# send request for new data inine @ 15s
5055
if ct_g + 15000 < millis():
51-
print("TOGGLE GEAR")
56+
LOGGER.info("TOGGLE GEAR")
5257
sm.SendData(GEAR_TOGGLE)
5358
ct_g = millis()
5459

@@ -58,7 +63,7 @@ def test_first_test(self):
5863
# check for data from myRequest
5964
data = sm.GetData(myRequest)
6065
if data is not None:
61-
print("Lat=%f Lon=%f Alt=%f Kohlsman=%.2f" % (
66+
LOGGER.info("Lat=%f Lon=%f Alt=%f Kohlsman=%.2f" % (
6267
data.Latitude,
6368
data.Longitude,
6469
data.Altitude,
@@ -68,15 +73,15 @@ def test_first_test(self):
6873
# check for data from myRequest2
6974
data = sm.GetData(myRequest2)
7075
if data is not None:
71-
print("Alt=%f GEAR=%d" % (
76+
LOGGER.info("Alt=%f GEAR=%d" % (
7277
data.ALTITUDE,
7378
data.GEAR
7479
))
7580

7681
# check for data from AUTOPILOTRequest
7782
data = sm.GetData(AUTOPILOTRequest)
7883
if data is not None:
79-
print("AUTOPILOT_MASTER: %d" % (
84+
LOGGER.info("AUTOPILOT_MASTER: %d" % (
8085
data.AUTOPILOT_MASTER
8186
))
8287

0 commit comments

Comments
 (0)