view weatherlog/reader_test.py @ 5:885bff085edf

Add remote logger class for eventual HTTP writer.
author Paul Fisher <paul@pfish.zone>
date Sat, 28 Sep 2019 19:28:22 -0400
parents 1abd0cc4caa4
children
line wrap: on
line source

import itertools
import unittest

from . import reader


class ReasonableTest(unittest.TestCase):

    def test_temp(self):
        for good_temp in (-40, 0, 20, 36.4, 40, 60):
            self.assertTrue(reader._is_reasonable_temp(good_temp))
        for bad_temp in (-273, -41, 69):
            self.assertFalse(reader._is_reasonable_temp(bad_temp))

    def test_rh(self):
        for good_rh in (0, 10.0, 55.5, 90):
            self.assertTrue(reader._is_reasonable_rh(good_rh))
        for bad_rh in (-1, 101):
            self.assertFalse(reader._is_reasonable_rh(bad_rh))


class StableTest(unittest.TestCase):

    def test_not_enough(self):
        with self.assertRaises(ValueError):
            reader._last_stable((), epsilon=1.0)
        with self.assertRaises(ValueError):
            reader._last_stable((1.0,), epsilon=1.0)
        with self.assertRaises(ValueError):
            reader._last_stable((1.0, 1.5), epsilon=1.0)
        with self.assertRaises(ValueError):
            reader._last_stable((1.0, 1.0, 1.0), epsilon=1.0, count=4)

    def test_wild(self):
        perms = itertools.permutations((1.0, 99.9, 1.2))
        for perm in perms:
            with self.assertRaises(ValueError):
                reader._last_stable(perm, epsilon=0.5)

    def test_good(self):
        perms = itertools.permutations((1.0, 1.3, 1.5, 66.6, -1))
        for perm in perms:
            self.assertEqual(reader._last_stable(perm, epsilon=1.01), 1.3)
        perms_less = itertools.permutations((1.0, 1.5))
        for perm in perms_less:
            self.assertEqual(
                reader._last_stable(perm, epsilon=0.51, count=2), 1.5)


if __name__ == '__main__':
    unittest.main()