Skip to content

Commit ce2fc9a

Browse files
committed
update power config unit tests
1 parent 68a7ba5 commit ce2fc9a

File tree

1 file changed

+22
-10
lines changed

1 file changed

+22
-10
lines changed

tests/test_rs_power_config.py

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,50 +17,62 @@
1717
PowerConfigPolynomialNotFoundException
1818
)
1919

20+
def test_not_loaded():
21+
pwrcfg = RsPowerConfig()
22+
assert False == pwrcfg.is_loaded()
23+
2024
def test_invalid_power_config_filepath():
2125
with pytest.raises(PowerConfigFileNotFoundException):
22-
RsPowerConfig(filepath='abc.json')
26+
RsPowerConfig().load('abc.json')
2327

2428
def test_invalid_json_content():
2529
with pytest.raises(PowerConfigParsingException):
26-
RsPowerConfig(filepath='tests/data/invalid_power_config.json')
30+
RsPowerConfig().load('tests/data/invalid_power_config.json')
2731

2832
def test_invalid_json_ref():
2933
with pytest.raises(PowerConfigParsingException):
30-
RsPowerConfig(filepath='tests/data/invalid_json_ref_power_config.json')
34+
RsPowerConfig().load('tests/data/invalid_json_ref_power_config.json')
3135

3236
def test_invalid_power_config_schema():
3337
with pytest.raises(PowerConfigSchemaValidationException):
34-
RsPowerConfig(filepath='tests/data/invalid_schema_power_config.json')
38+
RsPowerConfig().load('tests/data/invalid_schema_power_config.json')
3539

3640
def test_get_coeff_with_not_exist_component():
37-
pwrcfg = RsPowerConfig(filepath='tests/data/power_config.json')
41+
pwrcfg = RsPowerConfig()
42+
pwrcfg.load('tests/data/power_config.json')
3843
with pytest.raises(PowerConfigComponentNotFoundException):
3944
pwrcfg.get_coeff(ElementType.FABRIC_LE, "TEST1")
4045

4146
def test_get_coeff_with_not_exist_coeff():
42-
pwrcfg = RsPowerConfig(filepath='tests/data/power_config.json')
47+
pwrcfg = RsPowerConfig()
48+
pwrcfg.load('tests/data/power_config.json')
4349
with pytest.raises(PowerConfigCoeffNotFoundException):
4450
pwrcfg.get_coeff(ElementType.DSP, "ABC")
4551

4652
def test_get_coeff():
47-
pwrcfg = RsPowerConfig(filepath='tests/data/power_config.json')
53+
pwrcfg = RsPowerConfig()
54+
pwrcfg.load('tests/data/power_config.json')
4855
assert 0.1234 == pwrcfg.get_coeff(ElementType.DSP, "TEST1")
4956

5057
def test_get_polynomial_coeff_with_not_exist_component():
51-
pwrcfg = RsPowerConfig(filepath='tests/data/power_config.json')
58+
pwrcfg = RsPowerConfig()
59+
pwrcfg.load('tests/data/power_config.json')
5260
with pytest.raises(PowerConfigStaticComponentNotFoundException):
5361
pwrcfg.get_polynomial_coeff(ElementType.NOC, ScenarioType.TYPICAL)
5462

5563
def test_get_polynomial_coeff_with_not_exist_scenario():
56-
pwrcfg = RsPowerConfig(filepath='tests/data/power_config.json')
64+
pwrcfg = RsPowerConfig()
65+
pwrcfg.load('tests/data/power_config.json')
5766
with pytest.raises(PowerConfigPolynomialNotFoundException):
5867
pwrcfg.get_polynomial_coeff(ElementType.CLB, ScenarioType.WORSE)
5968

6069
def test_get_polynomial_coeff():
61-
pwrcfg = RsPowerConfig(filepath='tests/data/power_config.json')
70+
pwrcfg = RsPowerConfig()
71+
result = pwrcfg.load('tests/data/power_config.json')
6272
polynomials = pwrcfg.get_polynomial_coeff(ElementType.CLB, ScenarioType.TYPICAL)
6373
assert 1 == len(polynomials)
74+
assert True == result
75+
assert True == pwrcfg.is_loaded()
6476
assert 5 == polynomials[0].length
6577
assert 1.25 == polynomials[0].factor
6678
assert [0.1, 0.2, 0.3, 0.4, 0.5] == polynomials[0].coeffs

0 commit comments

Comments
 (0)