Mercurial > templog
annotate py/test.py @ 579:4a6e75ed2ed4
fix gpio chown script
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Mon, 30 Nov 2015 21:40:45 +0800 |
parents | 453c4c0eab3a |
children |
rev | line source |
---|---|
529 | 1 import io |
444 | 2 |
443 | 3 import unittest |
4 import sensor_ds18b20 | |
444 | 5 import params |
443 | 6 |
7 class TestSensors(unittest.TestCase): | |
8 def setUp(self): | |
572
453c4c0eab3a
syntax fixes, doesn't make sense yet for asyncio
Matt Johnston <matt@ucc.asn.au>
parents:
529
diff
changeset
|
9 self.sensors = sensor_ds18b20.SensorDS18B20(None) |
443 | 10 |
444 | 11 def test_sensors_regex(self): |
443 | 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 """ | |
447 | 15 val = self.sensors.do_sensor('blank', f1) |
443 | 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 """ | |
447 | 21 val = self.sensors.do_sensor('blank', f2) |
443 | 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 """ | |
447 | 27 val = self.sensors.do_sensor('blank', f3) |
443 | 28 self.assertEqual(val, -0.001) |
29 | |
444 | 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): | |
529 | 52 jsbuf = io.StringIO('{"fridge_setpoint": 999}') |
444 | 53 |
54 self.params.load(f=jsbuf) | |
55 self.assertEqual(self.params.fridge_setpoint, 999) | |
56 | |
57 with self.assertRaises(params.Params.Error): | |
529 | 58 jsbuf = io.StringIO('{"something_else": 999}') |
444 | 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): | |
529 | 65 jsbuf = io.StringIO() |
444 | 66 |
67 self.params.overshoot_delay = 123 | |
572
453c4c0eab3a
syntax fixes, doesn't make sense yet for asyncio
Matt Johnston <matt@ucc.asn.au>
parents:
529
diff
changeset
|
68 s = self.params.save_string() |
444 | 69 self.assertTrue('"overshoot_delay": 123' in s, msg=s) |
70 | |
443 | 71 unittest.main() |