コード例 #1
0
ファイル: bag_test.py プロジェクト: RichardFreeman/pyrsistent
def test_empty_bag():
    """
    creating an empty pbag returns a singleton.

    Note that this should NOT be relied upon in application code.
    """
    assert b() is b()
コード例 #2
0
def test_empty_bag():
    """
    creating an empty pbag returns a singleton.

    Note that this should NOT be relied upon in application code.
    """
    assert b() is b()
コード例 #3
0
ファイル: test_planning.py プロジェクト: pratikmallya/otter
    def assert_converge_clb_steps(self, clb_descs, clb_nodes, clb_steps,
                                  draining_timeout, now):
        """
        Run the converge function on the given a server with the given
        :class:`CLBDescription`s  and :class:`CLBNode`s, the given
        draining timeout, and the given time.

        Assert that the LB steps produced are equivalent to the given
        CLB steps.

        Run the converge function again, this time with a default
        :class:`RCv3Description` and a default :class:`RCv3Node` added, and
        assert that the LB steps produced are equivalent to the given
        CLB steps plus a RCv3 node removal, because RCv3 nodes are not
        drainable and are hence unaffected by timeouts.
        """
        without_rcv3_steps = converge(
            DesiredGroupState(server_config={}, capacity=0,
                              draining_timeout=draining_timeout),
            s(server('abc',
                     ServerState.ACTIVE,
                     servicenet_address=self.address,
                     desired_lbs=s(*clb_descs))),
            s(*clb_nodes),
            now=now)

        self.assertEqual(self._filter_only_lb_steps(without_rcv3_steps),
                         b(*clb_steps))

        rcv3_desc = RCv3Description(
            lb_id='e762e42a-8a4e-4ffb-be17-f9dc672729b2')
        rcv3_step = BulkRemoveFromRCv3(
            lb_node_pairs=s(('e762e42a-8a4e-4ffb-be17-f9dc672729b2', 'abc')))

        with_rcv3_steps = converge(
            DesiredGroupState(server_config={}, capacity=0,
                              draining_timeout=draining_timeout),
            s(server('abc',
                     ServerState.ACTIVE,
                     servicenet_address=self.address,
                     desired_lbs=s(rcv3_desc, *clb_descs))),
            s(RCv3Node(node_id='43a39c18-8cad-4bb1-808e-450d950be289',
                       cloud_server_id='abc', description=rcv3_desc),
              *clb_nodes),
            now=now)

        self.assertEqual(self._filter_only_lb_steps(with_rcv3_steps),
                         b(rcv3_step, *clb_steps))
コード例 #4
0
def test_pbag_is_unorderable():
    with pytest.raises(TypeError):
        _ = b(1) < b(2)

    with pytest.raises(TypeError):
        _ = b(1) <= b(2)

    with pytest.raises(TypeError):
        _ = b(1) > b(2)

    with pytest.raises(TypeError):
        _ = b(1) >= b(2)
コード例 #5
0
ファイル: bag_test.py プロジェクト: RichardFreeman/pyrsistent
def test_pbag_is_unorderable():
    with pytest.raises(TypeError):
        _ = b(1) < b(2)

    with pytest.raises(TypeError):
        _ = b(1) <= b(2)

    with pytest.raises(TypeError):
        _ = b(1) > b(2)

    with pytest.raises(TypeError):
        _ = b(1) >= b(2)
コード例 #6
0
def test_not_contains():
    assert 1 not in b(2)
コード例 #7
0
def test_sub():
    assert b(1, 2, 3, 3) - b(3, 4) == b(1, 2, 3)
コード例 #8
0
def test_count_duplicate():
    assert b(1, 1).count(1) == 2
コード例 #9
0
ファイル: bag_test.py プロジェクト: RichardFreeman/pyrsistent
def test_supports_hash():
    assert hash(b(1, 2)) == hash(b(2, 1))
コード例 #10
0
def test_literalish_works():
    assert b(1, 2) == pbag([1, 2])
コード例 #11
0
def test_eq_same_order():
    assert b(1, 2, 1) == b(1, 2, 1)
コード例 #12
0
ファイル: bag_test.py プロジェクト: RichardFreeman/pyrsistent
def test_eq_empty():
    assert b() == b()
コード例 #13
0
def test_repr_empty():
    assert repr(b()) == 'pbag([])'
コード例 #14
0
ファイル: bag_test.py プロジェクト: RichardFreeman/pyrsistent
def test_remove_nonfinal():
    assert b().add(1).add(1).remove(1) == b(1)
コード例 #15
0
ファイル: bag_test.py プロジェクト: RichardFreeman/pyrsistent
def test_remove_nonexistent():
    with pytest.raises(KeyError) as excinfo:
        b().remove(1)
    assert str(excinfo.exconly()) == 'KeyError: 1'
コード例 #16
0
ファイル: bag_test.py プロジェクト: RichardFreeman/pyrsistent
def test_add():
    assert b().add(1) == b(1)
コード例 #17
0
ファイル: bag_test.py プロジェクト: RichardFreeman/pyrsistent
def test_repr_elements():
    assert repr(b(1, 2)) in ('pbag([1, 2])', 'pbag([2, 1])')
コード例 #18
0
ファイル: bag_test.py プロジェクト: RichardFreeman/pyrsistent
def test_repr_empty():
    assert repr(b()) == 'pbag([])'
コード例 #19
0
def test_and():
    assert b(1, 2, 2, 3, 3, 3) & b(2, 3, 3, 4) == b(2, 3, 3)
コード例 #20
0
ファイル: bag_test.py プロジェクト: RichardFreeman/pyrsistent
def test_literalish_works():
    assert b(1, 2) == pbag([1, 2])
コード例 #21
0
ファイル: bag_test.py プロジェクト: RichardFreeman/pyrsistent
def test_empty_truthiness():
    assert b(1)
    assert not b()
コード例 #22
0
ファイル: bag_test.py プロジェクト: RichardFreeman/pyrsistent
def test_neq():
    assert b(1) != b()
コード例 #23
0
def test_add():
    assert b().add(1) == b(1)
コード例 #24
0
ファイル: bag_test.py プロジェクト: RichardFreeman/pyrsistent
def test_eq_same_order():
    assert b(1, 2, 1) == b(1, 2, 1)
コード例 #25
0
def test_eq_empty():
    assert b() == b()
コード例 #26
0
ファイル: bag_test.py プロジェクト: RichardFreeman/pyrsistent
def test_eq_different_order():
    assert b(2, 1, 2) == b(1, 2, 2)
コード例 #27
0
def test_count_non_existent():
    assert b().count(1) == 0
コード例 #28
0
ファイル: bag_test.py プロジェクト: RichardFreeman/pyrsistent
def test_count_non_existent():
    assert b().count(1) == 0
コード例 #29
0
def test_length_unique():
    assert len(b(1)) == 1
コード例 #30
0
ファイル: bag_test.py プロジェクト: RichardFreeman/pyrsistent
def test_count_unique():
    assert b(1).count(1) == 1
コード例 #31
0
def test_contains():
    assert 1 in b(1)
コード例 #32
0
ファイル: bag_test.py プロジェクト: RichardFreeman/pyrsistent
def test_count_duplicate():
    assert b(1, 1).count(1) == 2
コード例 #33
0
def test_add():
    assert b(3, 3, 3, 2, 2, 1) + b(4, 3, 2, 1) == b(4, 3, 3, 3, 3, 2, 2, 2, 1,
                                                    1)
コード例 #34
0
def test_supports_weakref():
    import weakref
    weakref.ref(b(1))
コード例 #35
0
def test_or():
    assert b(1, 2, 2, 3, 3, 3) | b(1, 2, 3, 4, 4) == b(1, 2, 2, 3, 3, 3, 4, 4)
コード例 #36
0
def test_hash_in_dict():
    assert {b(1, 2, 3, 3): "hello"}[b(3, 3, 2, 1)] == "hello"
コード例 #37
0
ファイル: bag_test.py プロジェクト: RichardFreeman/pyrsistent
def test_length_empty():
    assert len(b()) == 0
コード例 #38
0
ファイル: bag_test.py プロジェクト: RichardFreeman/pyrsistent
def test_hash_in_dict():
    assert {b(1,2,3,3): "hello"}[b(3,3,2,1)] == "hello"
コード例 #39
0
def test_supports_hash():
    assert hash(b(1, 2)) == hash(b(2, 1))
コード例 #40
0
ファイル: bag_test.py プロジェクト: RichardFreeman/pyrsistent
def test_length_unique():
    assert len(b(1)) == 1
コード例 #41
0
def test_empty_truthiness():
    assert b(1)
    assert not b()
コード例 #42
0
ファイル: bag_test.py プロジェクト: RichardFreeman/pyrsistent
def test_length_duplicates():
    assert len(b(1, 1)) == 2
コード例 #43
0
def test_repr_elements():
    assert repr(b(1, 2)) in ('pbag([1, 2])', 'pbag([2, 1])')
コード例 #44
0
ファイル: bag_test.py プロジェクト: sarum90/pyrsistent
def test_supports_weakref():
    import weakref
    weakref.ref(b(1))
コード例 #45
0
def test_remove_nonfinal():
    assert b().add(1).add(1).remove(1) == b(1)
コード例 #46
0
ファイル: bag_test.py プロジェクト: RichardFreeman/pyrsistent
def test_length_multiple_elements():
    assert len(b(1, 1, 2, 3)) == 4
コード例 #47
0
def test_remove_nonexistent():
    with pytest.raises(KeyError) as excinfo:
        b().remove(1)
    assert str(excinfo.exconly()) == 'KeyError: 1'
コード例 #48
0
ファイル: bag_test.py プロジェクト: RichardFreeman/pyrsistent
def test_iter_duplicates():
    assert list(b(1, 1)) == [1, 1]
コード例 #49
0
def test_neq():
    assert b(1) != b()
コード例 #50
0
ファイル: bag_test.py プロジェクト: RichardFreeman/pyrsistent
def test_iter_multiple_elements():
    assert list(b(1, 2, 2)) in ([1, 2, 2], [2, 2, 1])
コード例 #51
0
def test_eq_different_order():
    assert b(2, 1, 2) == b(1, 2, 2)
コード例 #52
0
ファイル: bag_test.py プロジェクト: RichardFreeman/pyrsistent
def test_contains():
    assert 1 in b(1)
コード例 #53
0
def test_count_unique():
    assert b(1).count(1) == 1
コード例 #54
0
ファイル: bag_test.py プロジェクト: RichardFreeman/pyrsistent
def test_not_contains():
    assert 1 not in b(2)
コード例 #55
0
def test_length_empty():
    assert len(b()) == 0
コード例 #56
0
def test_length_duplicates():
    assert len(b(1, 1)) == 2
コード例 #57
0
ファイル: bag_test.py プロジェクト: sarum90/pyrsistent
def test_and():
    assert b(1, 2, 2, 3, 3, 3) & b(2, 3, 3, 4) == b(2, 3, 3)
コード例 #58
0
ファイル: bag_test.py プロジェクト: sarum90/pyrsistent
def test_add():
    assert b(3, 3, 3, 2, 2, 1) + b(4, 3, 2, 1) == b(4,
                                                    3, 3, 3, 3,
                                                    2, 2, 2,
                                                    1, 1)
コード例 #59
0
def test_length_multiple_elements():
    assert len(b(1, 1, 2, 3)) == 4
コード例 #60
0
def test_iter_multiple_elements():
    assert list(b(1, 2, 2)) in ([1, 2, 2], [2, 2, 1])