summaryrefslogtreecommitdiff
path: root/test/test_codegen.py
diff options
context:
space:
mode:
authorDaniel Friesel <daniel.friesel@uos.de>2020-07-02 09:35:48 +0200
committerDaniel Friesel <daniel.friesel@uos.de>2020-07-02 09:35:48 +0200
commitf1a9e8b419c3b0836989565fa462d7c67a4bc9b9 (patch)
treefc2560ee18f910636d1138f150da8782c59a44e8 /test/test_codegen.py
parent915826fd9144809f33a9ecdc8beb4b244581a045 (diff)
blacken test code
Diffstat (limited to 'test/test_codegen.py')
-rwxr-xr-xtest/test_codegen.py170
1 files changed, 88 insertions, 82 deletions
diff --git a/test/test_codegen.py b/test/test_codegen.py
index 981117b..ce565d6 100755
--- a/test/test_codegen.py
+++ b/test/test_codegen.py
@@ -5,84 +5,74 @@ from dfatool.codegen import get_simulated_accountingmethod
import unittest
example_json_1 = {
- 'parameters': ['datarate', 'txbytes', 'txpower'],
- 'initial_param_values': [None, None, None],
- 'state': {
- 'IDLE': {
- 'power': {
- 'static': 5,
- }
- },
- 'TX': {
- 'power': {
- 'static': 100,
- 'function': {
- 'raw': 'regression_arg(0) + regression_arg(1)'
- ' * parameter(txpower)',
- 'regression_args': [100, 2]
+ "parameters": ["datarate", "txbytes", "txpower"],
+ "initial_param_values": [None, None, None],
+ "state": {
+ "IDLE": {"power": {"static": 5,}},
+ "TX": {
+ "power": {
+ "static": 100,
+ "function": {
+ "raw": "regression_arg(0) + regression_arg(1)"
+ " * parameter(txpower)",
+ "regression_args": [100, 2],
},
}
},
},
- 'transitions': [
+ "transitions": [
{
- 'name': 'init',
- 'origin': ['UNINITIALIZED', 'IDLE'],
- 'destination': 'IDLE',
- 'duration': {
- 'static': 50000,
- },
- 'set_param': {
- 'txpower': 10
- },
+ "name": "init",
+ "origin": ["UNINITIALIZED", "IDLE"],
+ "destination": "IDLE",
+ "duration": {"static": 50000,},
+ "set_param": {"txpower": 10},
},
{
- 'name': 'setTxPower',
- 'origin': 'IDLE',
- 'destination': 'IDLE',
- 'duration': {'static': 120},
- 'energy ': {'static': 10000},
- 'arg_to_param_map': {0: 'txpower'},
- 'argument_values': [[10, 20, 30]],
+ "name": "setTxPower",
+ "origin": "IDLE",
+ "destination": "IDLE",
+ "duration": {"static": 120},
+ "energy ": {"static": 10000},
+ "arg_to_param_map": {0: "txpower"},
+ "argument_values": [[10, 20, 30]],
},
{
- 'name': 'send',
- 'origin': 'IDLE',
- 'destination': 'TX',
- 'duration': {
- 'static': 10,
- 'function': {
- 'raw': 'regression_arg(0) + regression_arg(1)'
- ' * function_arg(1)',
- 'regression_args': [48, 8],
+ "name": "send",
+ "origin": "IDLE",
+ "destination": "TX",
+ "duration": {
+ "static": 10,
+ "function": {
+ "raw": "regression_arg(0) + regression_arg(1)" " * function_arg(1)",
+ "regression_args": [48, 8],
},
},
- 'energy': {
- 'static': 3,
- 'function': {
- 'raw': 'regression_arg(0) + regression_arg(1)'
- ' * function_arg(1)',
- 'regression_args': [3, 5],
+ "energy": {
+ "static": 3,
+ "function": {
+ "raw": "regression_arg(0) + regression_arg(1)" " * function_arg(1)",
+ "regression_args": [3, 5],
},
},
- 'arg_to_param_map': {1: 'txbytes'},
- 'argument_values': [['"foo"', '"hodor"'], [3, 5]],
- 'argument_combination': 'zip',
+ "arg_to_param_map": {1: "txbytes"},
+ "argument_values": [['"foo"', '"hodor"'], [3, 5]],
+ "argument_combination": "zip",
},
{
- 'name': 'txComplete',
- 'origin': 'TX',
- 'destination': 'IDLE',
- 'is_interrupt': 1,
- 'timeout': {
- 'static': 2000,
- 'function': {
- 'raw': 'regression_arg(0) + regression_arg(1)'
- ' * parameter(txbytes)',
- 'regression_args': [500, 16],
+ "name": "txComplete",
+ "origin": "TX",
+ "destination": "IDLE",
+ "is_interrupt": 1,
+ "timeout": {
+ "static": 2000,
+ "function": {
+ "raw": "regression_arg(0) + regression_arg(1)"
+ " * parameter(txbytes)",
+ "regression_args": [500, 16],
},
},
- }
+ },
],
}
@@ -91,9 +81,11 @@ class TestCG(unittest.TestCase):
def test_statetransition_immediate(self):
pta = PTA.from_json(example_json_1)
pta.set_random_energy_model()
- pta.state['IDLE'].power.value = 9
- cg = get_simulated_accountingmethod('static_statetransition_immediate')(pta, 1000000, 'uint8_t', 'uint8_t', 'uint8_t', 'uint8_t')
- cg.current_state = pta.state['IDLE']
+ pta.state["IDLE"].power.value = 9
+ cg = get_simulated_accountingmethod("static_statetransition_immediate")(
+ pta, 1000000, "uint8_t", "uint8_t", "uint8_t", "uint8_t"
+ )
+ cg.current_state = pta.state["IDLE"]
cg.sleep(7)
self.assertEqual(cg.get_energy(), 9 * 7)
pta.transitions[1].energy.value = 123
@@ -102,8 +94,10 @@ class TestCG(unittest.TestCase):
cg.pass_transition(pta.transitions[1])
self.assertEqual(cg.get_energy(), (9 * 7 + 123 + 123) % 256)
- cg = get_simulated_accountingmethod('static_statetransition_immediate')(pta, 100000, 'uint8_t', 'uint8_t', 'uint8_t', 'uint8_t')
- cg.current_state = pta.state['IDLE']
+ cg = get_simulated_accountingmethod("static_statetransition_immediate")(
+ pta, 100000, "uint8_t", "uint8_t", "uint8_t", "uint8_t"
+ )
+ cg.current_state = pta.state["IDLE"]
cg.sleep(7)
self.assertEqual(cg.get_energy(), 0)
cg.sleep(15)
@@ -111,8 +105,10 @@ class TestCG(unittest.TestCase):
cg.sleep(90)
self.assertEqual(cg.get_energy(), 900 % 256)
- cg = get_simulated_accountingmethod('static_statetransition_immediate')(pta, 100000, 'uint8_t', 'uint8_t', 'uint8_t', 'uint16_t')
- cg.current_state = pta.state['IDLE']
+ cg = get_simulated_accountingmethod("static_statetransition_immediate")(
+ pta, 100000, "uint8_t", "uint8_t", "uint8_t", "uint16_t"
+ )
+ cg.current_state = pta.state["IDLE"]
cg.sleep(7)
self.assertEqual(cg.get_energy(), 0)
cg.sleep(15)
@@ -120,10 +116,12 @@ class TestCG(unittest.TestCase):
cg.sleep(90)
self.assertEqual(cg.get_energy(), 900)
- pta.state['IDLE'].power.value = 9 # -> 90 uW
+ pta.state["IDLE"].power.value = 9 # -> 90 uW
pta.transitions[1].energy.value = 1 # -> 100 pJ
- cg = get_simulated_accountingmethod('static_statetransition_immediate')(pta, 1000000, 'uint8_t', 'uint8_t', 'uint8_t', 'uint8_t', 1e-5, 1e-5, 1e-10)
- cg.current_state = pta.state['IDLE']
+ cg = get_simulated_accountingmethod("static_statetransition_immediate")(
+ pta, 1000000, "uint8_t", "uint8_t", "uint8_t", "uint8_t", 1e-5, 1e-5, 1e-10
+ )
+ cg.current_state = pta.state["IDLE"]
cg.sleep(10) # 10 us
self.assertEqual(cg.get_energy(), 90 * 10)
cg.pass_transition(pta.transitions[1])
@@ -134,9 +132,11 @@ class TestCG(unittest.TestCase):
def test_statetransition(self):
pta = PTA.from_json(example_json_1)
pta.set_random_energy_model()
- pta.state['IDLE'].power.value = 9
- cg = get_simulated_accountingmethod('static_statetransition')(pta, 1000000, 'uint8_t', 'uint8_t', 'uint8_t', 'uint8_t')
- cg.current_state = pta.state['IDLE']
+ pta.state["IDLE"].power.value = 9
+ cg = get_simulated_accountingmethod("static_statetransition")(
+ pta, 1000000, "uint8_t", "uint8_t", "uint8_t", "uint8_t"
+ )
+ cg.current_state = pta.state["IDLE"]
cg.sleep(7)
self.assertEqual(cg.get_energy(), 9 * 7)
pta.transitions[1].energy.value = 123
@@ -148,9 +148,11 @@ class TestCG(unittest.TestCase):
def test_state_immediate(self):
pta = PTA.from_json(example_json_1)
pta.set_random_energy_model()
- pta.state['IDLE'].power.value = 9
- cg = get_simulated_accountingmethod('static_state_immediate')(pta, 1000000, 'uint8_t', 'uint8_t', 'uint8_t', 'uint8_t')
- cg.current_state = pta.state['IDLE']
+ pta.state["IDLE"].power.value = 9
+ cg = get_simulated_accountingmethod("static_state_immediate")(
+ pta, 1000000, "uint8_t", "uint8_t", "uint8_t", "uint8_t"
+ )
+ cg.current_state = pta.state["IDLE"]
cg.sleep(7)
self.assertEqual(cg.get_energy(), 9 * 7)
pta.transitions[1].energy.value = 123
@@ -162,9 +164,11 @@ class TestCG(unittest.TestCase):
def test_state(self):
pta = PTA.from_json(example_json_1)
pta.set_random_energy_model()
- pta.state['IDLE'].power.value = 9
- cg = get_simulated_accountingmethod('static_state')(pta, 1000000, 'uint8_t', 'uint8_t', 'uint8_t', 'uint8_t')
- cg.current_state = pta.state['IDLE']
+ pta.state["IDLE"].power.value = 9
+ cg = get_simulated_accountingmethod("static_state")(
+ pta, 1000000, "uint8_t", "uint8_t", "uint8_t", "uint8_t"
+ )
+ cg.current_state = pta.state["IDLE"]
cg.sleep(7)
self.assertEqual(cg.get_energy(), 9 * 7)
pta.transitions[1].energy.value = 123
@@ -173,8 +177,10 @@ class TestCG(unittest.TestCase):
cg.pass_transition(pta.transitions[1])
self.assertEqual(cg.get_energy(), 9 * 7)
- cg = get_simulated_accountingmethod('static_state')(pta, 1000000, 'uint8_t', 'uint16_t', 'uint16_t', 'uint16_t')
+ cg = get_simulated_accountingmethod("static_state")(
+ pta, 1000000, "uint8_t", "uint16_t", "uint16_t", "uint16_t"
+ )
-if __name__ == '__main__':
+if __name__ == "__main__":
unittest.main()