summaryrefslogtreecommitdiffstats
path: root/test/test_common.py
blob: e7f1c0a8d62d22aabe205b9819809fc306235e42 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# -*- coding: utf-8 -*-
"""Tests for the common routines."""

__author__ = 'Diego Elio Pettenò'
__email__ = 'flameeyes@flameeyes.eu'
__copyright__ = 'Copyright © 2013, Diego Elio Pettenò'
__license__ = 'GPL v3 or later'

import os
import sys
import unittest

import mock

sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))

from glucometerutils import common
from glucometerutils import exceptions

class TestCommon(unittest.TestCase):
  def setUp(self):
    pass

  def testGlucoseConversion(self):
    self.assertEqual(
      5.56, common.ConvertGlucoseUnit(
        100, common.UNIT_MGDL, common.UNIT_MMOLL))

    self.assertEqual(
      5.56, common.ConvertGlucoseUnit(
        100, common.UNIT_MGDL))

    self.assertEqual(
      180, common.ConvertGlucoseUnit(
        10, common.UNIT_MMOLL, common.UNIT_MGDL))

    self.assertEqual(
      180, common.ConvertGlucoseUnit(
        10, common.UNIT_MMOLL))

    self.assertEqual(
      100, common.ConvertGlucoseUnit(
        100, common.UNIT_MGDL, common.UNIT_MGDL))

    self.assertEqual(
      10, common.ConvertGlucoseUnit(
        10, common.UNIT_MMOLL, common.UNIT_MMOLL))

    self.assertRaises(
      exceptions.InvalidGlucoseUnit,
      common.ConvertGlucoseUnit, common.UNIT_MMOLL, 'foo')

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