Skip to content

Commit c0eb3cb

Browse files
committed
update tests
1 parent 8cd738d commit c0eb3cb

5 files changed

Lines changed: 154 additions & 62 deletions

File tree

tools/README.md

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,25 +28,31 @@ 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] [-m {source,default}] -i IPADDRESS -u USERNAME -p PASSWORD -k KEY
31+
usage: tests.py [-h] [-c CONFIGURATION] [-m] [-v] -u USERNAME -p PASSWORD [-i IPADDRESS] [-k KEY] [-s SERIALNUMBER]
3232
3333
E3DC tests
3434
3535
options:
3636
-h, --help show this help message and exit
37-
-c CONFIG, --config CONFIG
38-
config of E3DC
39-
-m {source,default}, --module {source,default}
40-
E3DC module source to use for test
37+
-c CONFIGURATION, --configuration CONFIGURATION
38+
configuration of E3DC
39+
-m, --module use locally installed E3DC module for test
40+
-v, --verbose use local E3DC module for test
4141
4242
required named arguments:
43-
-i IPADDRESS, --ipaddress IPADDRESS
44-
IP address of E3DC
4543
-u USERNAME, --username USERNAME
4644
username of E3DC
4745
-p PASSWORD, --password PASSWORD
4846
password of E3DC
49-
-k KEY, --key KEY key of E3DC
47+
48+
required named arguments for local connection:
49+
-i IPADDRESS, --ipaddress IPADDRESS
50+
IP address of E3DC
51+
-k KEY, --key KEY rscp key of E3DC
52+
53+
required named arguments for web connection:
54+
-s SERIALNUMBER, --serialnumber SERIALNUMBER
55+
serialnumber of E3DC
5056
```
5157

5258
## Run tests for different python versions
@@ -56,24 +62,32 @@ The script `testcontainers.py` wil run the `tests`, using docker, for multiple P
5662
### usage
5763

5864
```
59-
usage: testcontainers.py [-h] [-l LIST] [-c CONFIG] [-m {source,default}] -i IPADDRESS -u USERNAME -p PASSWORD -k KEY
65+
usage: testcontainers.py [-h] [-l LIST] [-c CONFIGURATION] [-m MODULE] [-v] -u USERNAME -p PASSWORD [-i IPADDRESS] [-k KEY]
66+
[-s SERIALNUMBER]
6067
6168
E3DC testcontainers
6269
6370
options:
6471
-h, --help show this help message and exit
6572
-l LIST, --list LIST list of Python versions to test with
66-
-c CONFIG, --config CONFIG
67-
config of E3DC
68-
-m {source,default}, --module {source,default}
69-
E3DC module source to use for test
73+
-c CONFIGURATION, --configuration CONFIGURATION
74+
configuration of E3DC
75+
-m MODULE, --module MODULE
76+
specify E3DC module version to be installed for tests. Use local to install from sources
77+
-v, --verbose use local E3DC module for test
7078
7179
required named arguments:
72-
-i IPADDRESS, --ipaddress IPADDRESS
73-
IP address of E3DC
7480
-u USERNAME, --username USERNAME
7581
username of E3DC
7682
-p PASSWORD, --password PASSWORD
7783
password of E3DC
78-
-k KEY, --key KEY key of E3DC
84+
85+
required named arguments for local connection:
86+
-i IPADDRESS, --ipaddress IPADDRESS
87+
IP address of E3DC
88+
-k KEY, --key KEY rscp key of E3DC
89+
90+
required named arguments for web connection:
91+
-s SERIALNUMBER, --serialnumber SERIALNUMBER
92+
serialnumber of E3DC
7993
```

tools/convert_rscp_tags.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,12 @@
2626
exit(1)
2727
input = jsbeautifier.beautify(str(source.content, encoding="utf-8"))
2828

29-
rscpTagsFromJS = re.search(
30-
r"var rscpTags = {(.*?)getHexTag.*?}", input, re.DOTALL
31-
).group(1)
29+
rscpTagsFromJS = re.search(r"var rscpTags = {(.*?)getHexTag.*?}", input, re.DOTALL)
3230

33-
lines = rscpTagsFromJS.splitlines()
31+
if rscpTagsFromJS is None:
32+
exit(1)
33+
34+
lines = rscpTagsFromJS.group(1).splitlines()
3435

3536
print("class RscpTag(Enum):")
3637
print(

tools/testcontainers.py

Lines changed: 57 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ def __init__(
1818
ipAddress,
1919
username,
2020
password,
21-
key,
2221
configuration,
23-
module,
22+
key="",
23+
serialNumber="",
2424
version="3.8",
2525
):
2626
"""The init method for Testcontainers."""
@@ -46,8 +46,8 @@ def __init__(
4646
"USERNAME": username,
4747
"PASSWORD": password,
4848
"KEY": key,
49+
"SERIALNUMBER": serialNumber,
4950
"CONFIG": configuration,
50-
"MODULE": module,
5151
},
5252
)
5353

@@ -57,10 +57,11 @@ def exec_cmd_stream(self, command):
5757
for data in stream:
5858
print(data.decode(), end="")
5959

60-
def exec_cmd(self, command):
60+
def exec_cmd(self, command, verbose=True):
6161
"""Execute a command and validate return code."""
6262
result, output = self.container.exec_run(cmd=command)
63-
print(output.decode())
63+
if verbose:
64+
print(output.decode())
6465
if result != 0:
6566
exit(1)
6667

@@ -76,37 +77,72 @@ def remove(self):
7677
help="list of Python versions to test with",
7778
default='["3.8", "3.9", "3.10", "3.11", "3.12"]',
7879
)
79-
parser.add_argument("-c", "--config", help="config of E3DC", default="{}")
80+
parser.add_argument("-c", "--configuration", help="configuration of E3DC", default="{}")
8081
parser.add_argument(
8182
"-m",
8283
"--module",
83-
help="E3DC module source to use for test",
84-
choices=["source", "default"],
85-
default="source",
84+
help="specify E3DC module version to be installed for tests. Use local to install from sources",
85+
default="local",
8686
)
87-
requiredNamed = parser.add_argument_group("required named arguments")
88-
requiredNamed.add_argument(
89-
"-i", "--ipaddress", help="IP address of E3DC", required=True
87+
parser.add_argument(
88+
"-v",
89+
"--verbose",
90+
action="store_true",
91+
help="use local E3DC module for test",
9092
)
93+
requiredNamed = parser.add_argument_group("required named arguments")
9194
requiredNamed.add_argument("-u", "--username", help="username of E3DC", required=True)
9295
requiredNamed.add_argument("-p", "--password", help="password of E3DC", required=True)
93-
requiredNamed.add_argument("-k", "--key", help="key of E3DC", required=True)
96+
97+
requiredNamedLocal = parser.add_argument_group(
98+
"required named arguments for local connection"
99+
)
100+
requiredNamedLocal.add_argument("-i", "--ipaddress", help="IP address of E3DC")
101+
requiredNamedLocal.add_argument("-k", "--key", help="rscp key of E3DC")
102+
103+
requiredNamedWeb = parser.add_argument_group(
104+
"required named arguments for web connection"
105+
)
106+
requiredNamedWeb.add_argument("-s", "--serialnumber", help="serialnumber of E3DC")
107+
108+
args = vars(parser.parse_args())
109+
110+
if args["serialnumber"] and (args["ipaddress"] or args["key"]):
111+
print("either provide require arguments for web or local connection")
112+
exit(2)
113+
elif args["serialnumber"] is None and not (args["ipaddress"] and args["key"]):
114+
print("for local connection ipaddress and key are required")
115+
exit(2)
116+
94117
args = vars(parser.parse_args())
95118

96119
for version in json.loads(args["list"]):
97-
print("Starting test on Python " + version + ":")
120+
if args["verbose"]:
121+
print("Starting test on Python " + version + ":")
98122
testcontainers = Testcontainers(
99123
ipAddress=args["ipaddress"],
100124
username=args["username"],
101125
password=args["password"],
102126
key=args["key"],
103-
configuration=args["config"],
104-
module=args["module"],
127+
configuration=args["configuration"],
128+
serialNumber=args["serialnumber"],
105129
version=version,
106130
)
107-
testcontainers.exec_cmd("pip install .")
108-
testcontainers.exec_cmd(
109-
"sh -c 'python tools/tests.py -i $IPADDRESS -u $USERNAME -p $PASSWORD -k $KEY -c $CONFIG -m $MODULE'"
110-
)
131+
cmd = "sh -c 'python tools/tests.py -u $USERNAME -p $PASSWORD -c $CONFIG"
132+
if args["module"] == "local":
133+
testcontainers.exec_cmd("pip install .", args["verbose"])
134+
else:
135+
testcontainers.exec_cmd(
136+
"pip install pye3dc=={}".format(args["module"]), args["verbose"]
137+
)
138+
cmd = cmd + " -m"
139+
if args["key"]:
140+
cmd = cmd + " -i $IPADDRESS -k $KEY"
141+
else:
142+
cmd = cmd + " -s $SERIALNUMBER"
143+
if args["verbose"]:
144+
cmd = cmd + " -v'"
145+
else:
146+
cmd = cmd + "'"
147+
testcontainers.exec_cmd(cmd)
111148
testcontainers.remove()
112-
print()

tools/tests.py

Lines changed: 54 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -22,44 +22,75 @@ def printJson(obj):
2222

2323

2424
parser = argparse.ArgumentParser(description="E3DC tests")
25-
parser.add_argument("-c", "--config", help="config of E3DC", default="{}")
25+
parser.add_argument("-c", "--configuration", help="configuration of E3DC", default="{}")
2626
parser.add_argument(
2727
"-m",
2828
"--module",
29-
help="E3DC module source to use for test",
30-
choices=["source", "default"],
31-
default="source",
29+
action="store_false",
30+
help="use locally installed E3DC module for test",
3231
)
33-
requiredNamed = parser.add_argument_group("required named arguments")
34-
requiredNamed.add_argument(
35-
"-i", "--ipaddress", help="IP address of E3DC", required=True
32+
parser.add_argument(
33+
"-v",
34+
"--verbose",
35+
action="store_true",
36+
help="use local E3DC module for test",
3637
)
38+
requiredNamed = parser.add_argument_group("required named arguments")
3739
requiredNamed.add_argument("-u", "--username", help="username of E3DC", required=True)
3840
requiredNamed.add_argument("-p", "--password", help="password of E3DC", required=True)
39-
requiredNamed.add_argument("-k", "--key", help="key of E3DC", required=True)
41+
42+
requiredNamedLocal = parser.add_argument_group(
43+
"required named arguments for local connection"
44+
)
45+
requiredNamedLocal.add_argument("-i", "--ipaddress", help="IP address of E3DC")
46+
requiredNamedLocal.add_argument("-k", "--key", help="rscp key of E3DC")
47+
48+
requiredNamedWeb = parser.add_argument_group(
49+
"required named arguments for web connection"
50+
)
51+
requiredNamedWeb.add_argument("-s", "--serialnumber", help="serialnumber of E3DC")
52+
4053
args = vars(parser.parse_args())
4154

42-
if args["module"] == "source":
55+
if args["serialnumber"] and (args["ipaddress"] or args["key"]):
56+
print("either provide require arguments for web or local connection")
57+
exit(2)
58+
elif args["serialnumber"] is None and not (args["ipaddress"] and args["key"]):
59+
print("for local connection ipaddress and key are required")
60+
exit(2)
61+
62+
if args["module"]:
4363
import sys
4464
from pathlib import Path
4565

4666
sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
4767
import e3dc
4868

49-
print("Running Test for E3DC from sources!\n")
69+
if args["verbose"]:
70+
print("Running Test for E3DC from sources!\n")
5071
else:
5172
import e3dc
5273

53-
print("Running Test for E3DC {}\n".format(e3dc.__version__))
74+
if args["verbose"]:
75+
print("Running Test for E3DC {}\n".format(e3dc.__version__))
5476

55-
e3dc_obj = e3dc.E3DC(
56-
e3dc.E3DC.CONNECT_LOCAL,
57-
ipAddress=args["ipaddress"],
58-
username=args["username"],
59-
password=args["password"],
60-
key=args["key"],
61-
configuration=json.loads(args["config"]),
62-
)
77+
if args["serialnumber"]:
78+
e3dc_obj = e3dc.E3DC(
79+
e3dc.E3DC.CONNECT_WEB,
80+
username=args["username"],
81+
password=args["password"],
82+
serialNumber=args["serialnumber"],
83+
configuration=json.loads(args["configuration"]),
84+
)
85+
else:
86+
e3dc_obj = e3dc.E3DC(
87+
e3dc.E3DC.CONNECT_LOCAL,
88+
ipAddress=args["ipaddress"],
89+
username=args["username"],
90+
password=args["password"],
91+
key=args["key"],
92+
configuration=json.loads(args["configuration"]),
93+
)
6394

6495
methods = [
6596
"poll",
@@ -81,7 +112,9 @@ def printJson(obj):
81112
]
82113

83114
for method in methods:
84-
print(method + "():")
115+
if args["verbose"]:
116+
print("\n" + method + "():")
85117
method = getattr(e3dc_obj, method)
86118
printJson(method(keepAlive=True))
87-
print()
119+
120+
e3dc_obj.disconnect()

tools/validate.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/bash
2+
set -e
3+
echo "running flake8"
4+
flake8
5+
echo "running isort"
6+
isort ./ --check -q
7+
echo "running black"
8+
black ./ --check -q

0 commit comments

Comments
 (0)