Esempio n. 1
0
 def test_pump_get_default_filename(self):
     import os
     p = Pump("data/building_def.json")
     filename = p.out_filename
     p.get()
     self.assertTrue(os.path.isfile(filename))
     os.remove(filename)
Esempio n. 2
0
class PumpTests(unittest.TestCase):
    """
    Unit tests for the Pump class
    """
    def setUp(self):
        """
        setup for PumpTest class
        :return:
        """
        self.pump = Pump('127.0.0.1', 8000)

    def test_set_state(self):
        """
        test setting the state of pump
        :return:
        """

        self.pump.set_state = MagicMock(return_value=True)
        self.pump.set_state('PUMP_IN')
        self.pump.set_state.assert_called_with('PUMP_IN')

    def test_get_state(self):
        """
        test calling get state of pump
        :return:
        """
        self.pump.get_state = MagicMock(return_value=1)
        self.assertEqual(self.pump.get_state(), 1)
Esempio n. 3
0
 def test_large_case(self):
     from testgraph import TestGraph
     p = Pump("data/person_def.json")
     p.original_graph = TestGraph()
     p.update_data = {1: {u'uri': u'http://vivo.school.edu/individual/n25674',
                          u'action': u'REMOVE'}}
     [add, sub] = p.update()
     self.assertTrue(len(add) == 0 and len(sub) == 8)
Esempio n. 4
0
 def test_single_uri_case(self):
     from testgraph import TestGraph
     p = Pump("data/person_def.json")
     p.original_graph = TestGraph()
     p.update_data = {1: {u'uri': u'http://vivo.school.edu/individual/n2084211328',
                          u'action': u'Remove'}}
     [add, sub] = p.update()
     self.assertTrue(len(add) == 0 and len(sub) == 1)
Esempio n. 5
0
 def test_summarize(self):
     from testgraph import TestGraph
     p = Pump("data/person_def.json")
     p.original_graph = TestGraph()
     print p.update_def
     p.update_data = {1: {u'uri': u'http://vivo.school.edu/individual/n1723097935',
                          u'any1': u'1'}}
     print p.summarize()  # No exception thrown by summarize
Esempio n. 6
0
 def test_not_found(self):
     from rdflib import Graph
     p = Pump("data/person_def.json")
     p.original_graph = Graph()  # empty graph
     p.update_data = {1: {u'uri': u'http://vivo.school.edu/individual/n12345678',
                          u'action': u'Remove'}}
     [add, sub] = p.update()
     self.assertTrue(len(add) == 0 and len(sub) == 0)
Esempio n. 7
0
 def test_add_one_new_to_two(self):
     from testgraph import TestGraph
     p = Pump("data/grant_pi_def.json")
     p.original_graph = TestGraph()
     p.update_data = {1: {u'uri': u'http://vivo.school.edu/individual/n45',
                          u'pis': u'http://vivo.school.edu/individual/n1134'}}
     [add, sub] = p.update()
     self.assertTrue(
         len(add) == 3 and len(sub) == 6)
Esempio n. 8
0
 def test_none_to_empty(self):
     from testgraph import TestGraph
     p = Pump("data/grant_pi_def.json")
     p.original_graph = TestGraph()
     p.update_data = {1: {u'uri': u'http://vivo.school.edu/individual/n44',
                          u'pis': u'None'}}
     [add, sub] = p.update()
     self.assertTrue(
         len(add) == 0 and len(sub) == 0)
Esempio n. 9
0
 def test_inject_empty_original_graph(self):
     from rdflib import Graph, URIRef
     p = Pump()
     p.original_graph = Graph()
     p.update_data = {1: {u'uri': u'http://vivo.school.edu/individual/n8984374104', u'abbreviation': u'None'}}
     [add, sub] = p.update()
     self.assertTrue(
         len(add) == 1 and len(sub) == 0 and (None,
                                              URIRef("http://www.w3.org/1999/02/22-rdf-syntax-ns#type"),
                                              URIRef("http://vivoweb.org/ontology/core#Building")) in add)
Esempio n. 10
0
 def test_boolean_get(self):
     from pump.vivopump import read_csv
     p = Pump("data/faculty_boolean_def.json")
     p.get()
     data = read_csv('pump_data.txt', delimiter='\t')
     nfac = 0
     for row, vals in data.items():
         if vals['faculty'] == '1':
             nfac += 1
     self.assertEqual(5, nfac)
Esempio n. 11
0
    def test_unique_three_delete_not_found(self):
        from testgraph import TestGraph

        # Delete the zip code from an existing address that doesn't have a zip code.

        p = Pump("data/org_def.json")
        p.original_graph = TestGraph()
        p.update_data = {1: {u'uri': u'http://vivo.school.edu/individual/n3535', u'zip': u'None'}}
        [add, sub] = p.update()
        self.assertTrue(len(add) == 0 and len(sub) == 0)
Esempio n. 12
0
 def test_no_secondary_merge(self):
     from testgraph import TestGraph
     p = Pump("data/person_def.json")
     p.original_graph = TestGraph()
     p.update_data = {3: {u'uri': u'http://vivo.school.edu/individual/n710', u'action': u''},
                      4: {u'uri': u'http://vivo.school.edu/individual/n1723097935', u'action': u'a'},
                      7: {u'uri': u'http://vivo.school.edu/individual/n711', u'action': u'a'},
                      }
     [add, sub] = p.update()
     self.assertTrue(len(add) == 0 and len(sub) == 0)
Esempio n. 13
0
 def test_delete_unicode(self):
     from rdflib import URIRef, Literal
     from testgraph import TestGraph
     p = Pump("data/person_def.json")
     p.update_data = {1: {u'uri': u'http://vivo.school.edu/individual/n711', u'name': u'None'}}
     p.original_graph = TestGraph()
     [add, sub] = p.update()
     self.assertTrue(
         len(add) == 0 and len(sub) == 1 and (URIRef("http://vivo.school.edu/individual/n711"),
                                              URIRef("http://www.w3.org/2000/01/rdf-schema#label"),
                                              Literal("Ελληνικά")) in sub)
Esempio n. 14
0
    def test_multiple_one_change_nothing(self):
        from testgraph import TestGraph

        #  Do nothing if the multiple values specified match those in VIVO

        p = Pump("data/person_def.json")
        p.update_data = {1: {u'uri': u'http://vivo.school.edu/individual/n1723097935',
                             u'types': u'fac;person'}}
        p.original_graph = TestGraph()
        [add, sub] = p.update()
        self.assertTrue(len(add) == 0 and len(sub) == 0)
Esempio n. 15
0
 def test_add_without_datatype(self):
     from rdflib import URIRef, Literal
     from testgraph import TestGraph
     p = Pump("data/building_def.json")
     p.update_data = {1: {u'uri': u'http://vivo.school.edu/individual/n1001011525', u'url': u'http://a'}}
     p.original_graph = TestGraph()
     [add, sub] = p.update()
     self.assertTrue(
         len(add) == 4 and len(sub) == 0 and (None,
                                              URIRef("http://vivoweb.org/ontology/core#linkURI"),
                                              Literal("http://a")) in add)
Esempio n. 16
0
 def test_unique_one_add(self):
     from rdflib import URIRef, Literal
     from testgraph import TestGraph
     p = Pump()
     p.original_graph = TestGraph()
     p.update_data = {1: {u'uri': u'http://vivo.school.edu/individual/n2525', u'abbreviation': u'PH9'}}
     [add, sub] = p.update()
     self.assertTrue(
         len(add) == 1 and len(sub) == 0 and (URIRef("http://vivo.school.edu/individual/n2525"),
                                              URIRef("http://vivoweb.org/ontology/core#abbreviation"),
                                              Literal("PH9")) in add)
Esempio n. 17
0
 def test_unique_one_delete(self):
     from rdflib import URIRef, Literal, XSD
     from testgraph import TestGraph
     p = Pump()
     p.original_graph = TestGraph()
     p.update_data = {1: {u'uri': u'http://vivo.school.edu/individual/n1001011525', u'abbreviation': u'None'}}
     [add, sub] = p.update()
     self.assertTrue(
         len(add) == 0 and len(sub) == 1 and (URIRef("http://vivo.school.edu/individual/n1001011525"),
                                              URIRef("http://vivoweb.org/ontology/core#abbreviation"),
                                              Literal("JWRU", datatype=XSD.string)) in sub)
Esempio n. 18
0
    def test_uri_is_blank(self):
        from testgraph import TestGraph

        #  Use the URI when not found

        p = Pump("data/person_def.json")
        p.update_data = {1: {u'uri': u' ',
                             u'types': u'fac;person'}}
        p.original_graph = TestGraph()
        [add, sub] = p.update()
        self.assertTrue(len(add) == 2 and len(sub) == 0)
Esempio n. 19
0
 def test_change_with_datatype(self):
     from rdflib import URIRef, Literal, XSD
     from testgraph import TestGraph
     p = Pump("data/building_def.json")
     p.update_data = {1: {u'uri': u'http://vivo.school.edu/individual/n1001011525', u'abbreviation': u'PH9'}}
     p.original_graph = TestGraph()
     [add, sub] = p.update()
     self.assertTrue(
         len(add) == 1 and len(sub) == 1 and (URIRef("http://vivo.school.edu/individual/n1001011525"),
                                              URIRef("http://vivoweb.org/ontology/core#abbreviation"),
                                              Literal("PH9", datatype=XSD.string)) in add)
Esempio n. 20
0
 def test_change_without_lang(self):
     from rdflib import URIRef, Literal
     from testgraph import TestGraph
     p = Pump("data/org_def.json")
     p.update_data = {1: {u'uri': u'http://vivo.school.edu/individual/n2525', u'name': u'Ad ver tising'}}
     p.original_graph = TestGraph()
     [add, sub] = p.update()
     self.assertTrue(
         len(add) == 1 and len(sub) == 1 and (URIRef("http://vivo.school.edu/individual/n2525"),
                                              URIRef("http://www.w3.org/2000/01/rdf-schema#label"),
                                              Literal("Ad ver tising")) in add)
Esempio n. 21
0
    def test_uri_not_found(self):
        from testgraph import TestGraph

        #  Use the URI when not found

        p = Pump("data/person_def.json")
        p.update_data = {1: {u'uri': u'http://vivo.school.edu/individual/n1723097936',
                             u'types': u'fac;person'}}
        p.original_graph = TestGraph()
        [add, sub] = p.update()
        self.assertTrue(len(add) == 2 and len(sub) == 0)
Esempio n. 22
0
    def test_multiple_one_delete(self):
        from testgraph import TestGraph

        #  Empty the set of values

        p = Pump("data/person_def.json")
        p.original_graph = TestGraph()
        p.update_data = {1: {u'uri': u'http://vivo.school.edu/individual/n25674',
                             u'research_areas': u'None'}}
        [add, sub] = p.update()
        self.assertTrue(len(add) == 0 and len(sub) == 4)
Esempio n. 23
0
    def test_unique_three_add_partial_path(self):
        from rdflib import URIRef, Literal, XSD
        from testgraph import TestGraph

        p = Pump("data/grant_def.json")
        p.original_graph = TestGraph()
        p.update_data = {1: {u'uri': u'http://vivo.school.edu/individual/n55', u'start_date': u'2006-03-01'}}
        [add, sub] = p.update()
        self.assertTrue(
            len(add) == 3 and len(sub) == 0 and (None,
                                                 URIRef("http://vivoweb.org/ontology/core#dateTime"),
                                                 Literal("2006-03-01", datatype=XSD.datetime)) in add)
Esempio n. 24
0
 def test_add_two_to_empty(self):
     from rdflib import URIRef
     from testgraph import TestGraph
     p = Pump("data/grant_pi_def.json")
     p.original_graph = TestGraph()
     p.update_data = {1: {u'uri': u'http://vivo.school.edu/individual/n44',
                          u'pis': u'http://vivo.school.edu/individual/n1133;http://vivo.school.edu/individual/n3413'}}
     [add, sub] = p.update()
     self.assertTrue(
         len(add) == 6 and len(sub) == 0 and (URIRef("http://vivo.school.edu/individual/n44"),
                                              URIRef("http://vivoweb.org/ontology/core#relates"),
                                              None) in add)
Esempio n. 25
0
 def test_remove(self):
     from testgraph import TestGraph
     from rdflib import URIRef
     p = Pump("data/person_def.json")
     p.original_graph = TestGraph()
     p.update_data = {1: {u'uri': u'http://vivo.school.edu/individual/n25674',
                          u'any1': u'n'}}
     [add, sub] = p.update()
     self.assertTrue(len(add) == 0 and len(sub) == 1 and
                     (URIRef("http://vivo.school.edu/individual/n25674"),
                      URIRef("http://vivoweb.org/ontology/core#hasResearchArea"),
                      URIRef("http://any1")) in sub)
Esempio n. 26
0
 def test_tick(self):
     """
     Testing Sensor.tick
     """
     sensor = Sensor('127.0.0.1', '8000')
     sensor.measure = MagicMock(return_value=10)
     pump = Pump('127.0.0.1', '8000')
     pump.get_state = MagicMock(return_value='PUMP_OFF')
     pump.set_state = MagicMock(return_value='PUMP_OFF')
     decider = Decider(10, 0.1)
     decider.decide = MagicMock(return_value='PUMP_OFF')
     controller = Controller(sensor, pump, decider)
     self.assertTrue(controller.tick())
Esempio n. 27
0
    def test_uri_is_invalid(self):
        from testgraph import TestGraph

        #  Use the URI when not found

        p = Pump("data/person_def.json")
        p.update_data = {1: {u'uri': u'not a uri',
                             u'types': u'fac;person'}}
        p.original_graph = TestGraph()

        with self.assertRaises(Exception):
            [add, sub] = p.update()
            print add, sub
Esempio n. 28
0
    def test_integration_set_pump_state_fail(self):
        decider = Decider(target_height=3000, margin=500)
        pump = Pump('127.0.0.1', 8000)
        sensor = Sensor('127.0.0.1', 8000)

        pump.set_state = MagicMock(return_value=False)
        pump.get_state = MagicMock(return_value=Pump.PUMP_OFF)

        sensor.measure = MagicMock(return_value=3500)
        controller = Controller(sensor, pump, decider)

        result = controller.tick()
        self.assertEqual(result, False)
Esempio n. 29
0
    def test_unique_three_delete(self):
        from rdflib import URIRef, Literal, XSD
        from testgraph import TestGraph

        # Delete the zip code on an existing address

        p = Pump("data/org_def.json")
        p.original_graph = TestGraph()
        p.update_data = {1: {u'uri': u'http://vivo.school.edu/individual/n4545', u'zip': u'None'}}
        [add, sub] = p.update()
        self.assertTrue(
            len(add) == 0 and len(sub) == 1 and (None,
                                                 URIRef("http://www.w3.org/2006/vcard/ns#postalCode"),
                                                 Literal("32604", datatype=XSD.string)) in sub)
Esempio n. 30
0
 def test_show_merge(self):
     from testgraph import TestGraph
     p = Pump("data/person_def.json")
     p.original_graph = TestGraph()
     p.update_data = {1: {u'uri': u'http://vivo.school.edu/individual/n25674', u'action': u'b'},
                      2: {u'uri': u'http://vivo.school.edu/individual/n709', u'action': u'a1'},
                      3: {u'uri': u'http://vivo.school.edu/individual/n710', u'action': u''},
                      4: {u'uri': u'http://vivo.school.edu/individual/n1723097935', u'action': u'a1'},
                      5: {u'uri': u'http://vivo.school.edu/individual/n2084211328', u'action': u'a'},
                      6: {u'uri': u'http://vivo.school.edu/individual/n708', u'action': u'b1'},
                      7: {u'uri': u'http://vivo.school.edu/individual/n711', u'action': u'a1'},
                      }
     [add, sub] = p.update()
     self.assertTrue(len(add) == 2 and len(sub) == 6)
Esempio n. 31
0
    def test_unique_three_add(self):
        from rdflib import URIRef, Literal, XSD
        from testgraph import TestGraph

        # Add a start date to a grant.  There is no date time interval, so a full path will need to be created

        p = Pump("data/grant_def.json")
        p.original_graph = TestGraph()
        p.update_data = {1: {u'uri': u'http://vivo.school.edu/individual/n44', u'start_date': u'2015-03-01'}}
        [add, sub] = p.update()
        self.assertTrue(
            len(add) == 5 and len(sub) == 0 and (None,
                                                 URIRef("http://vivoweb.org/ontology/core#dateTime"),
                                                 Literal("2015-03-01", datatype=XSD.datetime)) in add)
Esempio n. 32
0
    def test_unique_three_add_to_existing(self):
        from rdflib import URIRef, Literal, XSD
        from testgraph import TestGraph

        # Add a zip code to an address already exists, the zip needs to be
        # added to the existing address

        p = Pump("data/org_def.json")
        p.original_graph = TestGraph()
        p.update_data = {1: {u'uri': u'http://vivo.school.edu/individual/n3535', u'zip': u'32653'}}
        [add, sub] = p.update()
        self.assertTrue(
            len(add) == 1 and len(sub) == 0 and (None,
                                                 URIRef("http://www.w3.org/2006/vcard/ns#postalCode"),
                                                 Literal("32653", datatype=XSD.string)) in add)
Esempio n. 33
0
    def test_unique_three_delete_datetime(self):
        from rdflib import URIRef, Literal, XSD
        from testgraph import TestGraph

        # WARNING: Delete start date value from existing datetime interval.  This may not be the desirable data
        # management action

        p = Pump("data/grant_def.json")
        p.original_graph = TestGraph()
        p.update_data = {1: {u'uri': u'http://vivo.school.edu/individual/n125', u'start_date': u'None'}}
        [add, sub] = p.update()
        self.assertTrue(
            len(add) == 0 and len(sub) == 1 and (None,
                                                 URIRef("http://vivoweb.org/ontology/core#dateTime"),
                                                 Literal("2010-04-01", datatype=XSD.datetime)) in sub)
Esempio n. 34
0
    def test_decider_current_action_pumpoff_height_in_target_and_margin_range(
            self):
        decider = Decider(target_height=5000, margin=1000)
        pump = Pump('127.0.0.1', 8000)
        sensor = Sensor('127.0.0.1', 8000)
        controller = Controller(sensor, pump, decider)

        #equal to target + margin case
        result = decider.decide(current_height=4000,
                                current_action=Pump.PUMP_OFF,
                                actions=controller.actions)
        self.assertEqual(result, Pump.PUMP_OFF)

        #equal to target + margin case
        result = decider.decide(current_height=4000,
                                current_action=Pump.PUMP_OFF,
                                actions=controller.actions)
        self.assertEqual(result, Pump.PUMP_OFF)

        #in the range of (target - margin to target + margin)
        result = decider.decide(current_height=5800,
                                current_action=Pump.PUMP_OFF,
                                actions=controller.actions)
        self.assertEqual(result, Pump.PUMP_OFF)

        #in the range of (target - margin to target + margin)
        result = decider.decide(current_height=4200,
                                current_action=Pump.PUMP_OFF,
                                actions=controller.actions)
        self.assertEqual(result, Pump.PUMP_OFF)
Esempio n. 35
0
    def setUp(self):
        """Set up controller for test"""

        self.sensor = Sensor('127.0.0.1', 8000)
        self.pump = Pump('127.0.0.1', 8000)
        self.decider = Decider(10, 0.05)
        self.controller = Controller(self.sensor, self.pump, self.decider)
 def setUp(self):
     """
     This method does a setup for integration testing raterregulation
     """
     self.pump = Pump('127.0.0.1', 1000)
     self.sensor = Sensor('127.0.0.2', 2000)
     self.decider = Decider(100, 0.05)
     self.controller = Controller(self.sensor, self.pump, self.decider)
Esempio n. 37
0
class ControllerTests(unittest.TestCase):
    """
    Unit tests for the Controller class
    """
    def setUp(self):
        """
        Set up method for test_controller
        """
        self.sensor = Sensor('127.0.0.1', 8000)
        self.sensor.measure = MagicMock(return_value=100)
        self.pump = Pump('127.0.0.1', 8000)
        self.pump.set_state = MagicMock(return_value=True)
        self.pump.get_state = MagicMock(return_value=self.pump.PUMP_OFF)
        self.decider = Decider(100, .10)
        self.decider.decide = MagicMock(return_value=self.pump.PUMP_OFF)
        self.controller = Controller(self.sensor, self.pump, self.decider)
        self.controller.tick()

        self.actions = {
            'PUMP_IN': self.pump.PUMP_IN,
            'PUMP_OUT': self.pump.PUMP_OUT,
            'PUMP_OFF': self.pump.PUMP_OFF
        }

    def test_controller(self):
        """
        Test controller and tick:
        1: Check sensor.measure for accuracy
        2: test pump.get_state for correct return
        3: decider.decide for correct 'decision'
        4: Test pump.set_state for expected mocked output
        5: Test sensor.measure return val is correct type
        6: Round-a-bout way of testing the try/except
        block of controller.tick() -- if pump.set_state
        returns False, it is because of a TypeError,
        checking that if it is False, it raises TypeError
        """
        self.assertEqual(100, self.sensor.measure())  # 1
        self.assertEqual(0, self.pump.get_state())  # 2
        self.assertEqual(0, self.decider.decide(100, 0, self.actions))  # 3
        self.assertEqual(True,
                         self.pump.set_state(self.actions['PUMP_OFF']))  # 4
        self.assertTrue(self.sensor.measure() == float(100))  # 5
        if self.pump.set_state(False):  # 6
            self.assertRaises(TypeError)
Esempio n. 38
0
 def test_decider_current_action_pump_off_height_less_than_target(self):
     decider = Decider(target_height=10000, margin=1000)
     pump = Pump('127.0.0.1', 8000)
     sensor = Sensor('127.0.0.1', 8000)
     controller = Controller(sensor, pump, decider)
     result = decider.decide(current_height=5000,
                             current_action=Pump.PUMP_OFF,
                             actions=controller.actions)
     self.assertEqual(result, Pump.PUMP_IN)
Esempio n. 39
0
    def setUp(self):
        """
        This method does a setup for unit testing Controller
        """
        self.pump = Pump('127.0.0.1', 1000)
        self.sensor = Sensor('127.0.0.2', 2000)
        self.decider = Decider(100, 0.05)

        self.controller = Controller(self.sensor, self.pump, self.decider)
Esempio n. 40
0
    def setUp(self):
        """
        setup
        :return:
        """
        self.pump = Pump('127.0.0.1', 8000)
        self.sensor = Sensor('127.1.1.3', 9000)
        self.decider = Decider(100, 0.05)

        self.controller = Controller(self.sensor, self.pump, self.decider)
Esempio n. 41
0
    def setUp(self):
        """
        Set up method for test_controller
        """
        self.sensor = Sensor('127.0.0.1', 8000)
        self.sensor.measure = MagicMock(return_value=100)
        self.pump = Pump('127.0.0.1', 8000)
        self.pump.set_state = MagicMock(return_value=True)
        self.pump.get_state = MagicMock(return_value=self.pump.PUMP_OFF)
        self.decider = Decider(100, .10)
        self.decider.decide = MagicMock(return_value=self.pump.PUMP_OFF)
        self.controller = Controller(self.sensor, self.pump, self.decider)
        self.controller.tick()

        self.actions = {
            'PUMP_IN': self.pump.PUMP_IN,
            'PUMP_OUT': self.pump.PUMP_OUT,
            'PUMP_OFF': self.pump.PUMP_OFF
        }
Esempio n. 42
0
 def setUp(self):
     """
     Setup for test_tick
     """
     self.sensor = Sensor('127.0.0.1', '8000')
     self.pump = Pump('127.0.0.1', '8001')
     self.decider = Decider(30, 0.05)
     self.sensor.measure = MagicMock(return_value=True)
     self.pump.set_state = MagicMock(return_value=True)
     self.pump.get_state = MagicMock(return_value="PUMP_IN")
     self.controller = Controller(self.sensor, self.pump, self.decider)
Esempio n. 43
0
    def test_decider_current_action_pumpoff_height_greater_target_and_margin(
            self):
        decider = Decider(target_height=1000, margin=200)
        pump = Pump('127.0.0.1', 8000)
        sensor = Sensor('127.0.0.1', 8000)
        controller = Controller(sensor, pump, decider)

        result = decider.decide(current_height=1250,
                                current_action=Pump.PUMP_OFF,
                                actions=controller.actions)
        self.assertEqual(result, Pump.PUMP_OUT)
Esempio n. 44
0
class PumpTests(unittest.TestCase):
    """
    This class performs a unit test on Pump
    """
    def setUp(self):
        """
        This method does a setup for unit testing Pump
        """
        self.pump = Pump('127.0.0.1', 1000)

    def test_set_state(self):
        """
        This method tests the set_state for Pump
        """
        self.pump.set_state = MagicMock(return_value=True)
        self.pump.set_state('PUMP_OUT')
        self.pump.set_state.assert_called_with('PUMP_OUT')

    def test_get_state(self):
        """
        This method tests the get_state for Pump
        """
        self.pump.get_state = MagicMock(return_value=1)
        self.assertEqual(self.pump.get_state(), 1)
Esempio n. 45
0
    def test_decide(self):
        """
        test decide method from Decider class
        """

        pump = Pump('127.0.0.1', 8000)

        actions = {
            'PUMP_IN': pump.PUMP_IN,
            'PUMP_OUT': pump.PUMP_OUT,
            'PUMP_OFF': pump.PUMP_OFF,
        }
        self.assertEqual(self.decider.decide(110, 'PUMP_OFF', actions), 1)
        self.assertEqual(self.decider.decide(60, 'PUMP_OFF', actions), -1)
        self.assertEqual(self.decider.decide(105, 'PUMP_OFF', actions), 0)
        self.assertEqual(self.decider.decide(120, 'PUMP_IN', actions), 0)
        self.assertEqual(self.decider.decide(90, 'PUMP_OUT', actions), 0)
        self.assertEqual(self.decider.decide(115, 'PUMP_OUT', actions), -1)
Esempio n. 46
0
    def test_decide(self):
        """
        This method performs a unit test on decide
        """

        pump = Pump('127.0.0.1', 1000)

        actions = {
            'PUMP_IN': pump.PUMP_IN,
            'PUMP_OUT': pump.PUMP_OUT,
            'PUMP_OFF': pump.PUMP_OFF,
        }

        self.assertEqual(self.decider.decide(130, 'PUMP_OFF', actions), 1)
        self.assertEqual(self.decider.decide(40, 'PUMP_OFF', actions), -1)
        self.assertEqual(self.decider.decide(105, 'PUMP_OFF', actions), 0)
        self.assertEqual(self.decider.decide(140, 'PUMP_IN', actions), 0)
        self.assertEqual(self.decider.decide(85, 'PUMP_OUT', actions), 0)
        self.assertEqual(self.decider.decide(110, 'PUMP_OUT', actions), -1)
 def test_all(self):
     """
     Run full test on all components of waterregulation
     """
     pump_address = Pump('127.0.0.1', '2048')
     sensor_address = Sensor('127.0.0.1', '2048')
     decider_margins = Decider(100, .10)
     controller_all = Controller(sensor_address, pump_address,
                                 decider_margins)
     controller_all.pump.set_state = MagicMock(return_value=True)
     for action in controller_all.actions.values():
         for water_level in range(25, 150, 100):
             # water level (mocked)
             controller_all.sensor.measure = \
                 MagicMock(return_value=water_level)
             # pump state (mocked)
             controller_all.pump.get_state = MagicMock(
                 return_value=decider_margins.decide(
                     water_level, action, controller_all.actions))
             controller_all.tick()
Esempio n. 48
0
 def setUp(self):
     """
     setup for PumpTest class
     :return:
     """
     self.pump = Pump('127.0.0.1', 8000)
Esempio n. 49
0
def main():
    """
    The main function.  Does the work of Simple VIVO
    :return: None
    """
    import sys
    import logging
    from datetime import datetime
    from pump.vivopump import get_args, DefNotFoundException, InvalidDefException
    from pump.pump import Pump

    logging.captureWarnings(True)
    logger = logging.getLogger(__name__)
    formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
    handler = logging.StreamHandler(sys.stderr)
    handler.setFormatter(formatter)
    logger.addHandler(handler)
    logger.setLevel(logging.DEBUG)

    return_code = 0
    print datetime.now(), "Start"
    args = get_args()

    #   Create a Pump and use it to perform the requested actions based on arguments

    try:
        p = Pump(args.defn, args.src)
    except DefNotFoundException:
        print args.defn, "definition file not found"
        sys.exit(1)
    except InvalidDefException as invalid:
        print "Invalid definition file", args.defn, "\n", invalid
        sys.exit(1)

    p.filter = not args.nofilters
    p.inter = args.inter
    p.intra = args.intra
    p.rdfprefix = args.rdfprefix
    p.uriprefix = args.uriprefix
    p.queryuri = args.queryuri
    p.username = args.username
    p.password = args.password
    p.prefix = args.prefix
    p.query_parms = {'queryuri': p.queryuri, 'username': p.username, 'password': p.password,
                     'uriprefix': p.uriprefix, 'prefix': p.prefix}

    if args.action == 'get':
        n_rows = p.get()
        print datetime.now(), n_rows, "rows in", args.src
    elif args.action == 'update':
        try:
            [add_graph, sub_graph] = p.update()
        except IOError:
            print args.src, "file not found"
            return_code = 1
        else:
            add_file = open(args.rdfprefix + '_add.nt', 'w')
            print >>add_file, add_graph.serialize(format='nt')
            add_file.close()
            sub_file = open(args.rdfprefix + '_sub.nt', 'w')
            print >>sub_file, sub_graph.serialize(format='nt')
            sub_file.close()
            print datetime.now(), len(add_graph), 'triples to add', len(sub_graph), 'triples to sub'
    elif args.action == 'summarize':
        print p.summarize()
    elif args.action == 'serialize':
        print p.serialize()
    elif args.action == 'test':
        test_result = p.test()
        print test_result
        if 'Check' in test_result:
            return_code = 1
    else:
        print datetime.now(), "Unknown action.  Try sv -h for help"
    print datetime.now(), "Finish"
    sys.exit(return_code)
Esempio n. 50
0
 def setUp(self):
     """
     This method does a setup for unit testing Pump
     """
     self.pump = Pump('127.0.0.1', 1000)
 def setUp(self):
     self.sensor = Sensor('127.0.0.1', '168')
     self.pump = Pump('127.0.0.1', '168')
     self.decider = Decider(10, 0.5)
     self.controller = Controller(self.sensor, self.pump, self.decider)