Mercurial > templog
annotate py/test.py @ 608:71f045231a07 rust
remove unused file
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Fri, 17 Feb 2017 23:07:33 +0800 |
parents | 74c3ae4e3307 |
children |
rev | line source |
---|---|
230 | 1 import io |
145 | 2 |
144 | 3 import unittest |
4 import sensor_ds18b20 | |
145 | 5 import params |
144 | 6 |
7 class TestSensors(unittest.TestCase): | |
8 def setUp(self): | |
273
74c3ae4e3307
syntax fixes, doesn't make sense yet for asyncio
Matt Johnston <matt@ucc.asn.au>
parents:
230
diff
changeset
|
9 self.sensors = sensor_ds18b20.SensorDS18B20(None) |
144 | 10 |
145 | 11 def test_sensors_regex(self): |
144 | 12 f1 = """6e 01 4b 46 7f ff 02 10 71 : crc=71 YES |
13 6e 01 4b 46 7f ff 02 10 71 t=22875 | |
14 """ | |
148 | 15 val = self.sensors.do_sensor('blank', f1) |
144 | 16 self.assertEqual(val, 22.875) |
17 | |
18 f2 = """6e 01 4b 46 7f ff 02 10 71 : crc=71 NO | |
19 6e 01 4b 46 7f ff 02 10 71 t=22875 | |
20 """ | |
148 | 21 val = self.sensors.do_sensor('blank', f2) |
144 | 22 self.assertEqual(val, None) |
23 | |
24 f3 = """6e 01 4b 46 7f ff 02 10 71 : crc=71 YES | |
25 6e 01 4b 46 7f ff 02 10 71 t=-1 | |
26 """ | |
148 | 27 val = self.sensors.do_sensor('blank', f3) |
144 | 28 self.assertEqual(val, -0.001) |
29 | |
145 | 30 class TestParams(unittest.TestCase): |
31 def setUp(self): | |
32 self.params = params.Params() | |
33 | |
34 def test_params_basic(self): | |
35 defparams = params.Params() | |
36 self.assertEqual(defparams.overshoot_factor, | |
37 params._FIELD_DEFAULTS['overshoot_factor']) | |
38 | |
39 # fetching a bad parameter fails | |
40 with self.assertRaises(KeyError): | |
41 x = self.params.param_that_doesnt_exist | |
42 | |
43 # setting a parameter | |
44 defparams.overshoot_factor = 8877 | |
45 self.assertEqual(defparams.overshoot_factor, 8877) | |
46 | |
47 # setting a bad parameter fails | |
48 with self.assertRaises(KeyError): | |
49 self.params.somewrongthing = 5 | |
50 | |
51 def test_params_load(self): | |
230 | 52 jsbuf = io.StringIO('{"fridge_setpoint": 999}') |
145 | 53 |
54 self.params.load(f=jsbuf) | |
55 self.assertEqual(self.params.fridge_setpoint, 999) | |
56 | |
57 with self.assertRaises(params.Params.Error): | |
230 | 58 jsbuf = io.StringIO('{"something_else": 999}') |
145 | 59 self.params.load(f=jsbuf) |
60 | |
61 with self.assertRaises(KeyError): | |
62 x = self.params.something_else | |
63 | |
64 def test_params_save(self): | |
230 | 65 jsbuf = io.StringIO() |
145 | 66 |
67 self.params.overshoot_delay = 123 | |
273
74c3ae4e3307
syntax fixes, doesn't make sense yet for asyncio
Matt Johnston <matt@ucc.asn.au>
parents:
230
diff
changeset
|
68 s = self.params.save_string() |
145 | 69 self.assertTrue('"overshoot_delay": 123' in s, msg=s) |
70 | |
144 | 71 unittest.main() |