def test_should_remove_specified_relationship():
    Vx = Variable()
    Vy = Variable()
    Rxy = Relationship(Vx, Vy)
    Rwz = Relationship(Variable(), Variable())
    Am = AssociationMatrix()
    Am.add_relationship(Rxy)
    Am.add_relationship(Rwz)
    Am.remove_relationship(Rwz)
    assert Am.relationships == {frozenset((Vx.uuid, Vy.uuid)): Rxy}
def test_should_return_requested_relationship():
    Rxy = Relationship(Variable(), Variable())
    Rwz = Relationship(Variable(), Variable())
    Am = AssociationMatrix()
    Am.add_relationship(Rxy)
    Am.add_relationship(Rwz)

    a = Am.get_relationship_from_sensors(Rxy.sensor_x, Rxy.sensor_y)
    assert a == Rxy

    b = Am.get_relationship_from_sensors(Rwz.sensor_x, Rwz.sensor_y)
    assert b == Rwz
def test_should_add_relationship_to_relationships():
    Vx = Variable()
    Vy = Variable()
    Rxy = Relationship(Vx, Vy)
    Am = AssociationMatrix()
    Am.add_relationship(Rxy)
    assert Am.relationships == {frozenset((Vx.uuid, Vy.uuid)): Rxy}
Ejemplo n.º 4
0
def test_should_push_to_subscribers():
    rel = Relationship(Variable(), Variable())
    sub = Mock()
    sub.on_data = MagicMock()
    rel.subscribe(sub)
    rel._push_to_subscribers(10)
    sub.on_data.assert_called_with(10)
    def __init__(self, sensor_x, sensor_y):
        """
        A Relationship takes two sensors and subscribes to them for computation
        :type sensor_y: Variable
        :type sensor_x: Variable
        """

        # The current aggregation of variable values before a new frame has
        # been generated
        self.current_iteration = {
            sensor_x.get_uuid(): [],
            sensor_y.get_uuid(): []
        }

        self.db_name = "spearframe.db"

        if not self.__frame_table_exists():
            self.__create_frame_table()

        # Create a frame for keeping up with all previous frames computed
        self.summed_frame = None

        # Current Frame
        self.frame = None

        self.x_last_direction = 0
        self.y_last_direction = 0

        # set up our parent class
        Relationship.__init__(self, sensor_x, sensor_y)

        # sensor_x
        self.x_mono_list = []

        # sensor_y
        self.y_mono_list = []

        self.current_frame_start_time = None
Ejemplo n.º 6
0
def test_should_have_last_pushed_value_as_none_on_initialization():
    relationship = Relationship(Variable(), Variable())
    assert relationship.get_last_pushed_value() is None
Ejemplo n.º 7
0
def test_should_allow_objects_to_subscribe():
    rel = Relationship(Variable(), Variable())
    assert len(rel.subscribers) == 0
    rel.subscribe(2)
    assert len(rel.subscribers) == 1 and rel.subscribers[0] == 2
Ejemplo n.º 8
0
def test_should_update_last_pushed_value_on_push():
    relationship = Relationship(Variable(), Variable())
    relationship._push_to_subscribers(1)
    assert relationship.get_last_pushed_value() is 1
Ejemplo n.º 9
0
def test_should_automatically_subscribe_to_variables():
    var1 = Variable()
    var2 = Variable()
    relationship = Relationship(var1, var2)
    assert var1.subscribers[relationship.get_uuid()] is not None
    assert var2.subscribers[relationship.get_uuid()] is not None
Ejemplo n.º 10
0
def test_should_have_personal_uuid():
    relationship = Relationship(Variable(), Variable())
    assert relationship.get_uuid() is not None
Ejemplo n.º 11
0
def test_should_should_throw_error_trying_clean_up():
    with pytest.raises(NotImplementedError) as excinfo:
        Relationship(Variable(), Variable()).clean_up()
    assert "Underlying algorithm should implement this" in str(excinfo.value)
Ejemplo n.º 12
0
def test_should_should_throw_error_trying_to_get_value_between_times():
    with pytest.raises(NotImplementedError) as excinfo:
        Relationship(Variable(), Variable()).get_value_between_times(1, 2)
    assert "Underlying algorithm should implement this" in str(excinfo.value)
Ejemplo n.º 13
0
def test_should_should_throw_error_trying_get_new_value_from_variables():
    with pytest.raises(NotImplementedError) as excinfo:
        Relationship(Variable(), Variable()).on_new_value(1, 1, 0, 1)
    assert "Underlying algorithm should implement this" in str(excinfo.value)
Ejemplo n.º 14
0
def test_should_should_throw_error_trying_to_grab_coefficient():
    with pytest.raises(NotImplementedError) as excinfo:
        Relationship(Variable(), Variable()).get_correlation_coefficient()
    assert "Underlying algorithm should implement this" in str(excinfo.value)
def rel_75():
    rel = Relationship(Variable(), Variable())
    rel.get_correlation_coefficient = MagicMock(return_value=0.75)
    return rel