summaryrefslogtreecommitdiff
path: root/test-cli/test/tests/qamper.py
blob: b3ab8b1185226a582968cdcb111c166500ab5cc1 (plain)
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
import unittest
from test.helpers.amper import Amper


class Qamper(unittest.TestCase):
    params = None

    # varlist: undercurrent, overcurrent
    def __init__(self, testname, testfunc, varlist):
        self.params = varlist
        super(Qamper, self).__init__(testfunc)

        if "undercurrent" in varlist:
            self._undercurrent = varlist["undercurrent"]
        else:
            raise Exception('undercurrent param inside Qamp must be defined')
        if "overcurrent" in varlist:
            self._overcurrent = varlist["overcurrent"]
        else:
            raise Exception('overcurrent param inside Qamp must be defined')
        self._testMethodDoc = testname

    def execute(self):
        amp = Amper()
        # open serial connection
        if not amp.open():
            self.fail("failed: can not open serial port")
            return
        # check if the amperimeter is connected and working
        if not amp.hello():
            self.fail("failed: can not communicate")
            return
        # get current value (in Amperes)
        result = amp.getCurrent()
        # close serial connection
        amp.close()
        # # In order to give a valid result it is importarnt to define an under current value
        if result > float(self._overcurrent):
            self.fail("failed: Overcurrent detected ( {} )".format(result))

        if result < float(self._undercurrent):
            self.fail("failed: Undercurrent detected ( {} )".format(result))