Mercurial > templog
diff py/test.py @ 145:6517ddee3187
few more bits
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Thu, 29 Nov 2012 23:50:40 +0800 |
parents | 482d7852b511 |
children | b32e5a11a4cb |
line wrap: on
line diff
--- a/py/test.py Mon Nov 26 23:21:03 2012 +0800 +++ b/py/test.py Thu Nov 29 23:50:40 2012 +0800 @@ -1,11 +1,15 @@ +#!/usr/bin/env python2.7 +import StringIO + import unittest import sensor_ds18b20 +import params class TestSensors(unittest.TestCase): def setUp(self): self.sensors = sensor_ds18b20.DS18B20s(None) - def test_re(self): + def test_sensors_regex(self): f1 = """6e 01 4b 46 7f ff 02 10 71 : crc=71 YES 6e 01 4b 46 7f ff 02 10 71 t=22875 """ @@ -24,4 +28,47 @@ val = self.sensors.do_sensor_name('blank', f3) self.assertEqual(val, -0.001) +class TestParams(unittest.TestCase): + def setUp(self): + self.params = params.Params() + + def test_params_basic(self): + defparams = params.Params() + self.assertEqual(defparams.overshoot_factor, + params._FIELD_DEFAULTS['overshoot_factor']) + + # fetching a bad parameter fails + with self.assertRaises(KeyError): + x = self.params.param_that_doesnt_exist + + # setting a parameter + defparams.overshoot_factor = 8877 + self.assertEqual(defparams.overshoot_factor, 8877) + + # setting a bad parameter fails + with self.assertRaises(KeyError): + self.params.somewrongthing = 5 + + def test_params_load(self): + jsbuf = StringIO.StringIO('{"fridge_setpoint": 999}') + + self.params.load(f=jsbuf) + self.assertEqual(self.params.fridge_setpoint, 999) + + with self.assertRaises(params.Params.Error): + jsbuf = StringIO.StringIO('{"something_else": 999}') + self.params.load(f=jsbuf) + + with self.assertRaises(KeyError): + x = self.params.something_else + + def test_params_save(self): + jsbuf = StringIO.StringIO() + + self.params.overshoot_delay = 123 + self.params.save(f=jsbuf) + + s = jsbuf.getvalue() + self.assertTrue('"overshoot_delay": 123' in s, msg=s) + unittest.main()