Skip to content

Commit 48d8c66

Browse files
authored
update tests (#97)
* update tests
1 parent 172575d commit 48d8c66

File tree

3 files changed

+47
-9
lines changed

3 files changed

+47
-9
lines changed

tools/README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,16 @@ The script `tests.py` will run all non altering methods for `pye3dc` for testing
2828
### usage
2929

3030
```
31-
usage: tests.py [-h] [-c CONFIG] -i IPADDRESS -u USERNAME -p PASSWORD -k KEY
31+
usage: tests.py [-h] [-c CONFIG] [-m {source,default}] -i IPADDRESS -u USERNAME -p PASSWORD -k KEY
3232
3333
E3DC tests
3434
3535
options:
3636
-h, --help show this help message and exit
3737
-c CONFIG, --config CONFIG
3838
config of E3DC
39+
-m {source,default}, --module {source,default}
40+
E3DC module source to use for test
3941
4042
required named arguments:
4143
-i IPADDRESS, --ipaddress IPADDRESS
@@ -54,7 +56,7 @@ The script `testcontainers.py` wil run the `tests`, using docker, for multiple P
5456
### usage
5557

5658
```
57-
usage: testcontainers.py [-h] [-l LIST] [-c CONFIG] -i IPADDRESS -u USERNAME -p PASSWORD -k KEY
59+
usage: testcontainers.py [-h] [-l LIST] [-c CONFIG] [-m {source,default}] -i IPADDRESS -u USERNAME -p PASSWORD -k KEY
5860
5961
E3DC testcontainers
6062
@@ -63,6 +65,8 @@ options:
6365
-l LIST, --list LIST list of Python versions to test with
6466
-c CONFIG, --config CONFIG
6567
config of E3DC
68+
-m {source,default}, --module {source,default}
69+
E3DC module source to use for test
6670
6771
required named arguments:
6872
-i IPADDRESS, --ipaddress IPADDRESS

tools/testcontainers.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ def __init__(
2020
password,
2121
key,
2222
configuration,
23+
module,
2324
version="3.8",
2425
):
2526
"""The init method for Testcontainers."""
@@ -46,6 +47,7 @@ def __init__(
4647
"PASSWORD": password,
4748
"KEY": key,
4849
"CONFIG": configuration,
50+
"MODULE": module,
4951
},
5052
)
5153

@@ -75,6 +77,13 @@ def remove(self):
7577
default='["3.8", "3.9", "3.10", "3.11", "3.12"]',
7678
)
7779
parser.add_argument("-c", "--config", help="config of E3DC", default="{}")
80+
parser.add_argument(
81+
"-m",
82+
"--module",
83+
help="E3DC module source to use for test",
84+
choices=["source", "default"],
85+
default="source",
86+
)
7887
requiredNamed = parser.add_argument_group("required named arguments")
7988
requiredNamed.add_argument(
8089
"-i", "--ipaddress", help="IP address of E3DC", required=True
@@ -92,11 +101,12 @@ def remove(self):
92101
password=args["password"],
93102
key=args["key"],
94103
configuration=args["config"],
104+
module=args["module"],
95105
version=version,
96106
)
97107
testcontainers.exec_cmd("pip install .")
98108
testcontainers.exec_cmd(
99-
"sh -c 'python tools/tests.py -i $IPADDRESS -u $USERNAME -p $PASSWORD -k $KEY -c $CONFIG'"
109+
"sh -c 'python tools/tests.py -i $IPADDRESS -u $USERNAME -p $PASSWORD -k $KEY -c $CONFIG -m $MODULE'"
100110
)
101111
testcontainers.remove()
102112
print()

tools/tests.py

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@
22

33
import argparse
44
import json
5+
import re
56
from datetime import date, datetime
67

7-
from e3dc import E3DC
8-
98

109
def json_serial(obj):
1110
"""JSON serializer for objects not serializable by default json code."""
@@ -16,11 +15,21 @@ def json_serial(obj):
1615

1716
def printJson(obj):
1817
"""Print a json object with a datetime obect."""
19-
print(json.dumps(obj, indent=2, default=json_serial))
18+
output = json.dumps(obj, indent=2, default=json_serial)
19+
output = re.sub(r"(.*\"serial.*\": \")(.*)(\",*)", r"\1redacted\3", output, re.M)
20+
output = re.sub(r"(.*\"serial.*\": )(\d+)(,*)", r"\g<1>0\g<3>", output, re.M)
21+
print(output)
2022

2123

2224
parser = argparse.ArgumentParser(description="E3DC tests")
2325
parser.add_argument("-c", "--config", help="config of E3DC", default="{}")
26+
parser.add_argument(
27+
"-m",
28+
"--module",
29+
help="E3DC module source to use for test",
30+
choices=["source", "default"],
31+
default="source",
32+
)
2433
requiredNamed = parser.add_argument_group("required named arguments")
2534
requiredNamed.add_argument(
2635
"-i", "--ipaddress", help="IP address of E3DC", required=True
@@ -30,8 +39,21 @@ def printJson(obj):
3039
requiredNamed.add_argument("-k", "--key", help="key of E3DC", required=True)
3140
args = vars(parser.parse_args())
3241

33-
e3dc = E3DC(
34-
E3DC.CONNECT_LOCAL,
42+
if args["module"] == "source":
43+
import sys
44+
from pathlib import Path
45+
46+
sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
47+
import e3dc
48+
49+
print("Running Test for E3DC from sources!\n")
50+
else:
51+
import e3dc
52+
53+
print("Running Test for E3DC {}\n".format(e3dc.__version__))
54+
55+
e3dc_obj = e3dc.E3DC(
56+
e3dc.E3DC.CONNECT_LOCAL,
3557
ipAddress=args["ipaddress"],
3658
username=args["username"],
3759
password=args["password"],
@@ -46,8 +68,10 @@ def printJson(obj):
4668
"get_db_data",
4769
"get_system_info",
4870
"get_system_status",
71+
"get_batteries",
4972
"get_battery_data",
5073
"get_batteries_data",
74+
"get_pvis",
5175
"get_pvi_data",
5276
"get_pvis_data",
5377
"get_powermeters",
@@ -58,6 +82,6 @@ def printJson(obj):
5882

5983
for method in methods:
6084
print(method + "():")
61-
method = getattr(e3dc, method)
85+
method = getattr(e3dc_obj, method)
6286
printJson(method(keepAlive=True))
6387
print()

0 commit comments

Comments
 (0)