def testInt(self):
        
        status = Status.get_status_holder("UnitTest")
        status.reset()
        self.assertNotEqual(status, None)

        i = status.create_status_element("TestInteger")
        self.assertEquals(i.get_name(), "TestInteger")

        x = status.get_status_element("TestInteger")
        self.assertEquals(x, i)

        # Test set and get values
        for j in range(0,10):
            i.set_value(j)
            self.assertEquals(i.get_value(), j)

        # Clean up
        status.remove_status_element(i)
        try:
            status.get_status_element("TestInteger")
            self.fail("Remove does not remove status element 'TestInteger'")
        except Status.NoSuchElementException, e:
            # Expected
            pass
    def testPolicy_PERIODIC(self):

        status = Status.get_status_holder("UnitTest")
        status.reset()

        reporter = TestPeriodicStatusReporter("Periodic, 0.4sec", 0.4)
        status.add_reporter(reporter)
        i = status.create_status_element("TestInteger")

        for x in range(0, 5):
            i.set_value(x)
            self.assertEquals(reporter.last_value, None) # Not updated yet
            
        time.sleep(1)
        
        assert reporter.last_value == 4

        for x in range(5, 9):
            self.assertEquals(reporter.last_value, 4) # Not updated yet
            i.set_value(x)
        time.sleep(1)

        self.assertEquals(reporter.last_value, 8)

        # Clean up
        status.remove_status_element(i)

        reporter.stop()
    def testPolicy_PERIODIC(self):

        status = Status.get_status_holder("UnitTest")
        status.reset()

        reporter = TestPeriodicStatusReporter("Periodic, 0.4sec", 0.4)
        status.add_reporter(reporter)
        i = status.create_status_element("TestInteger")

        for x in range(0, 5):
            i.set_value(x)
            self.assertEquals(reporter.last_value, None)  # Not updated yet

        time.sleep(1)

        assert reporter.last_value == 4

        for x in range(5, 9):
            self.assertEquals(reporter.last_value, 4)  # Not updated yet
            i.set_value(x)
        time.sleep(1)

        self.assertEquals(reporter.last_value, 8)

        # Clean up
        status.remove_status_element(i)

        reporter.stop()
    def testInt(self):

        status = Status.get_status_holder("UnitTest")
        status.reset()
        self.assertNotEqual(status, None)

        i = status.create_status_element("TestInteger")
        self.assertEquals(i.get_name(), "TestInteger")

        x = status.get_status_element("TestInteger")
        self.assertEquals(x, i)

        # Test set and get values
        for j in range(0, 10):
            i.set_value(j)
            self.assertEquals(i.get_value(), j)

        # Clean up
        status.remove_status_element(i)
        try:
            status.get_status_element("TestInteger")
            self.fail("Remove does not remove status element 'TestInteger'")
        except Status.NoSuchElementException, e:
            # Expected
            pass
    def testBasic(self):

        status = Status.get_status_holder("UnitTest")
        status.reset()
        
        self.assertNotEqual(status, None)

        self.assertEquals(status.get_name(), "UnitTest")
    def testBasic(self):

        status = Status.get_status_holder("UnitTest")
        status.reset()

        self.assertNotEqual(status, None)

        self.assertEquals(status.get_name(), "UnitTest")
    def testInvalid(self):
        status = Status.get_status_holder("UnitTest")
        status.reset()

        try:
            i = status.create_status_element(None)
            self.fail("Does not throw exception with no name")
        except AssertionError, e:
            pass
    def testInvalid(self):
        status = Status.get_status_holder("UnitTest")
        status.reset()

        try:
            i = status.create_status_element(None)
            self.fail("Does not throw exception with no name")
        except AssertionError, e:
            pass
    def test_LLReporter_element(self):

        status = Status.get_status_holder("UnitTest")
        status.reset()
        reporter = TestLivingLabPeriodicReporter("Living lab test reporter", 1.0)
        status.add_reporter(reporter)
        i = status.create_status_element("TestInteger")
        i.set_value(1233)
        
        reporter.wait_for_post(5.0)

        reporter.stop()
        time.sleep(1)
        
        self.assertEquals(len(reporter.get_errors()), 0)

        status.remove_status_element(i)
    def testPolicy_ON_CHANGE(self):

        status = Status.get_status_holder("UnitTest")
        status.reset()
        reporter = TestOnChangeStatusReporter("On change")
        status.add_reporter(reporter)
        i = status.create_status_element("TestInteger")

        for x in range(0, 10):
            i.set_value(x)
            if x != reporter.value:
                self.fail("Callback does not work for ON_CHANGE policy")
            if reporter.name != "TestInteger":
                self.fail("On_Change callback get's the wrong parameter, got '%s', expected 'TestInteger'"%reporter.name)

        # Clean up
        status.remove_status_element(i)
    def test_LLReporter_element(self):

        status = Status.get_status_holder("UnitTest")
        status.reset()
        reporter = TestLivingLabPeriodicReporter("Living lab test reporter",
                                                 1.0)
        status.add_reporter(reporter)
        i = status.create_status_element("TestInteger")
        i.set_value(1233)

        reporter.wait_for_post(5.0)

        reporter.stop()
        time.sleep(1)

        self.assertEquals(len(reporter.get_errors()), 0)

        status.remove_status_element(i)
    def test_LLReporter_event(self):

        status = Status.get_status_holder("UnitTest")
        status.reset()
        reporter = TestLivingLabPeriodicReporter("Living lab test reporter", 1.0)
        status.add_reporter(reporter)
        event = status.create_event("SomeEvent")
        event.add_value("123")
        event.add_value("456")
        status.add_event(event)
        
        reporter.wait_for_post(5.0)

        reporter.stop()
        time.sleep(1)
        
        self.assertEquals(len(reporter.get_errors()), 0)

        status.remove_event(event)
    def testPolicy_ON_CHANGE(self):

        status = Status.get_status_holder("UnitTest")
        status.reset()
        reporter = TestOnChangeStatusReporter("On change")
        status.add_reporter(reporter)
        i = status.create_status_element("TestInteger")

        for x in range(0, 10):
            i.set_value(x)
            if x != reporter.value:
                self.fail("Callback does not work for ON_CHANGE policy")
            if reporter.name != "TestInteger":
                self.fail(
                    "On_Change callback get's the wrong parameter, got '%s', expected 'TestInteger'"
                    % reporter.name)

        # Clean up
        status.remove_status_element(i)
    def test_LLReporter_event(self):

        status = Status.get_status_holder("UnitTest")
        status.reset()
        reporter = TestLivingLabPeriodicReporter("Living lab test reporter",
                                                 1.0)
        status.add_reporter(reporter)
        event = status.create_event("SomeEvent")
        event.add_value("123")
        event.add_value("456")
        status.add_event(event)

        reporter.wait_for_post(5.0)

        reporter.stop()
        time.sleep(1)

        self.assertEquals(len(reporter.get_errors()), 0)

        status.remove_event(event)
        except AssertionError, e:
            pass

        try:
            status.get_status_element(None)
            self.fail("Invalid get_status_element does not throw exception")
        except AssertionError, e:
            pass

        try:
            status.remove_status_element(None)
            self.fail("Invalid remove_status_element does not throw exception")
        except AssertionError, e:
            pass

        elem = Status.StatusElement("name", "description")
        try:
            status.remove_status_element(elem)
            self.fail("Invalid remove_status_element does not throw exception")
        except Status.NoSuchElementException, e:
            pass

    def testPolicy_ON_CHANGE(self):

        status = Status.get_status_holder("UnitTest")
        status.reset()
        reporter = TestOnChangeStatusReporter("On change")
        status.add_reporter(reporter)
        i = status.create_status_element("TestInteger")

        for x in range(0, 10):