-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest.py
More file actions
40 lines (30 loc) · 1.59 KB
/
test.py
File metadata and controls
40 lines (30 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/micropython
# -*- coding: utf-8 -*-
#
import yaml
import pprint
from config_loader import ConfigLoader
# read common values ┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈
print('begin test…')
config = ConfigLoader.configure()
kp_value = config["kros"]["motor"]["pid_controller"]["kp"]
if not isinstance(kp_value, float):
raise TypeError('kp was not a float value.')
print("\nkp: '{}'".format(kp_value))
calibrate_value = config["kros"]["motor"]["slew_limiter"]["calibrate"]
if not isinstance(calibrate_value, bool):
raise TypeError('calibrate was not a boolean value.')
print("\ncalibrate: '{}'".format(calibrate_value))
# re-parse imported string ┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈
yaml_data = pprint.pretty_print(config, return_text=True)
print('\nyaml type: {}'.format(type(yaml_data)))
print('\nparse imported configuration…')
dog_food = yaml.parse(yaml_data)
print('\ndog food: {}'.format(dog_food))
# dump ┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈
print('\ndump with indent of 4:\n')
yaml.dump(config)
_file_path = 'output.yaml'
print("\ndump to file '{}' with indent of 2:\n".format(_file_path))
yaml.dump(config, file_path=_file_path, indent=2)
print('complete.')