Exemplo n.º 1
0
def test_iterable():
    """
    PLists can be created from iterables even though they can't be len()
    hinted.
    """

    assert plist(iter("a")) == plist(iter("a"))
Exemplo n.º 2
0
def test_iterable():
    """
    PLists can be created from iterables even though they can't be len()
    hinted.
    """

    assert plist(iter("a")) == plist(iter("a"))
Exemplo n.º 3
0
def decode(obj):
    if isinstance(obj, ExtType):
        if obj.code == TYPE_PSET:
            unpacked_data = unpackb(obj.data, use_list=False, encoding='utf-8')
            return pset(decode(item) for item in unpacked_data)
        if obj.code == TYPE_PLIST:
            unpacked_data = unpackb(obj.data, use_list=False, encoding='utf-8')
            return plist(decode(item) for item in unpacked_data)
        if obj.code == TYPE_PBAG:
            unpacked_data = unpackb(obj.data, use_list=False, encoding='utf-8')
            return pbag(decode(item) for item in unpacked_data)
        if obj.code == TYPE_FUNC:
            module_name, func_name = unpackb(obj.data,
                                             use_list=False,
                                             encoding='utf-8')

            return getattr(sys.modules[module_name], func_name)
        module_name, class_name, *data = unpackb(obj.data,
                                                 use_list=False,
                                                 encoding='utf-8')
        cls = getattr(sys.modules[module_name], class_name)
        if obj.code == TYPE_MBOX:
            return cls.decode(data)
        return cls(*(decode(item) for item in data))
    if isinstance(obj, tuple):
        return pvector(decode(item) for item in obj)
    if isinstance(obj, dict):
        new_dict = dict()
        for key in obj.keys():
            new_dict[decode(key)] = decode(obj[key])
        return pmap(new_dict)
    return obj
Exemplo n.º 4
0
Arquivo: actor.py Projeto: tlvu/mochi
def decode(obj):
    if isinstance(obj, ExtType):
        if obj.code == TYPE_PSET:
            unpacked_data = unpackb(obj.data,
                                    use_list=False,
                                    encoding='utf-8')
            return pset(decode(item) for item in unpacked_data)
        if obj.code == TYPE_PLIST:
            unpacked_data = unpackb(obj.data,
                                    use_list=False,
                                    encoding='utf-8')
            return plist(decode(item) for item in unpacked_data)
        if obj.code == TYPE_PBAG:
            unpacked_data = unpackb(obj.data,
                                    use_list=False,
                                    encoding='utf-8')
            return pbag(decode(item) for item in unpacked_data)
        module_name, class_name, *data = unpackb(obj.data,
                                                 use_list=False,
                                                 encoding='utf-8')
        cls = getattr(sys.modules[module_name],
                      class_name)
        return cls(*(decode(item) for item in data))
    if isinstance(obj, tuple):
        return pvector(decode(item) for item in obj)
    if isinstance(obj, dict):
        new_dict = dict()
        for key in obj.keys():
            new_dict[decode(key)] = decode(obj[key])
        return pmap(new_dict)
    return obj
Exemplo n.º 5
0
    def perimeter_positions(self, game: Game):
        all_positions_set = pset(
            game.black_positions.union(game.white_positions))
        all_positions = plist(all_positions_set)

        horizon = s()
        while len(all_positions) > 0:
            head = all_positions.first
            all_positions = all_positions.rest
            neighbors = self.get_neighbors(head)
            horizon = horizon.union(neighbors)

        return horizon.difference(all_positions_set)
Exemplo n.º 6
0
def no_interesctions(point_map):
    """Finds all of the graph edges such that all nodes are connected and no
    edges 'intersect' on the 2d plane"""
    all_edges = pset([s(anchor, search)
                      for anchor in point_map.keys()
                      for search in point_map.keys()
                      if anchor != search])
    edges_by_distance = sorted(plist(all_edges), key=lambda y: edge_distance(y, point_map))

    edges = []
    for edge in edges_by_distance:
        pair_a = edge_to_pair(edge, point_map)
        if not any([find_affine_intersection(pair_a, edge_to_pair(y, point_map)) for y in edges]):
            edges.append(edge)

    return edges
Exemplo n.º 7
0
def no_interesctions(point_map):
    """Finds all of the graph edges such that all nodes are connected and no
    edges 'intersect' on the 2d plane"""
    all_edges = pset([
        s(anchor, search) for anchor in point_map.keys()
        for search in point_map.keys() if anchor != search
    ])
    edges_by_distance = sorted(plist(all_edges),
                               key=lambda y: edge_distance(y, point_map))

    edges = []
    for edge in edges_by_distance:
        pair_a = edge_to_pair(edge, point_map)
        if not any([
                find_affine_intersection(pair_a, edge_to_pair(y, point_map))
                for y in edges
        ]):
            edges.append(edge)

    return edges
Exemplo n.º 8
0
class JenkinsResultsTests(TestCase):
    """
    Tests for interpretation of build results from Jenkins.
    """
    @given(jenkins_build_results())
    def test_result_types(self, info):
        """
        Result always a tuple (`JenkinsResults`, Maybe[dict])
        """
        result, params = merge_pr.jenkins_info_from_response(info)
        self.assertIn(result, list(merge_pr.JenkinsResults.iterconstants()))
        if params is not None:
            self.assertIsInstance(params, dict)

    @given(jenkins_build_results(inQueue=just(True)))
    def test_in_queue(self, info):
        """
        Job with inQueue = True is `RUNNING`.
        """
        result, params = merge_pr.jenkins_info_from_response(info)
        self.assertEqual(merge_pr.JenkinsResults.RUNNING, result)
        self.assertEqual({}, params)

    @given(jenkins_build_results(inQueue=just(False), builds=NO_BUILDS))
    def test_builds_not_present(self, info):
        """
        Job without a builds list is `UNKNOWN`.
        """
        result, params = merge_pr.jenkins_info_from_response(info)
        self.assertEqual(merge_pr.JenkinsResults.UNKNOWN, result)
        self.assertEqual({}, params)

    @given(jenkins_build_results(inQueue=just(False), builds=just(plist())))
    def test_no_builds(self, info):
        """
        Job with empty builds list is `NOTRUN`.
        """
        result, params = merge_pr.jenkins_info_from_response(info)
        self.assertEqual(merge_pr.JenkinsResults.NOTRUN, result)
        self.assertEqual({}, params)
Exemplo n.º 9
0
def test_remove():
    assert plist([1, 2, 3, 2]).remove(2) == plist([1, 3, 2])
    assert plist([1, 2, 3]).remove(1) == plist([2, 3])
    assert plist([1, 2, 3]).remove(3) == plist([1, 2])
Exemplo n.º 10
0
def test_split_no_split_occurred():
    x = plist([1, 2])
    left_list, right_list = x.split(2)
    assert left_list is x
    assert right_list is plist()
Exemplo n.º 11
0
def test_index_invalid_type():
    with pytest.raises(TypeError) as e:
        plist([1, 2, 3])['foo']

    assert 'cannot be interpreted' in str(e)
Exemplo n.º 12
0
def test_repr():
    assert str(plist()) == "plist([])"
    assert str(plist([1, 2, 3])) == "plist([1, 2, 3])"
Exemplo n.º 13
0
def test_rest_return_self_on_empty_list():
    assert plist().rest is plist()
Exemplo n.º 14
0
def test_cons_empty_list():
    assert plist().cons(0) == plist([0])
Exemplo n.º 15
0
def test_instantiate_large_list():
    assert plist(range(1000)).first == 0
Exemplo n.º 16
0
def test_iteration():
    assert list(plist()) == []
    assert list(plist([1, 2, 3])) == [1, 2, 3]
Exemplo n.º 17
0
def test_supports_weakref():
    import weakref
    weakref.ref(plist())
    weakref.ref(plist([1, 2]))
Exemplo n.º 18
0
def test_mcons():
    assert plist([1, 2]).mcons([3, 4]) == plist([4, 3, 1, 2])
Exemplo n.º 19
0
def test_remove_missing_element():
    with pytest.raises(ValueError):
        plist([1, 2]).remove(3)

    with pytest.raises(ValueError):
        plist().remove(2)
Exemplo n.º 20
0
def test_remove():
    assert plist([1, 2, 3, 2]).remove(2) == plist([1, 3, 2])
    assert plist([1, 2, 3]).remove(1) == plist([2, 3])
    assert plist([1, 2, 3]).remove(3) == plist([1, 2])
Exemplo n.º 21
0
def test_split_empty_list():
    left_list, right_list = plist().split(2)
    assert left_list == plist()
    assert right_list == plist()
Exemplo n.º 22
0
def test_mcons():
    assert plist([1, 2]).mcons([3, 4]) == plist([4, 3, 1, 2])
Exemplo n.º 23
0
def test_iteration():
    assert list(plist()) == []
    assert list(plist([1, 2, 3])) == [1, 2, 3]
Exemplo n.º 24
0
def test_cons():
    assert plist([1, 2, 3]).cons(0) == plist([0, 1, 2, 3])
Exemplo n.º 25
0
def test_len():
    assert len(plist([1, 2, 3])) == 3
    assert len(plist()) == 0
Exemplo n.º 26
0
def test_cons_empty_list():
    assert plist().cons(0) == plist([0])
Exemplo n.º 27
0
def test_reverse():
    assert plist([1, 2, 3]).reverse() == plist([3, 2, 1])
    assert reversed(plist([1, 2, 3])) == plist([3, 2, 1])

    assert plist().reverse() == plist()
    assert reversed(plist()) == plist()
Exemplo n.º 28
0
def test_truthiness():
    assert plist([1])
    assert not plist()
Exemplo n.º 29
0
def test_indexing_on_empty_list():
    with pytest.raises(IndexError):
        plist()[0]
Exemplo n.º 30
0
def test_len():
    assert len(plist([1, 2, 3])) == 3
    assert len(plist()) == 0
Exemplo n.º 31
0
def test_slicing_take():
    assert plist([1, 2, 3])[:2] == plist([1, 2])
Exemplo n.º 32
0
def test_first_illegal_on_empty_list():
    with pytest.raises(AttributeError):
        plist().first
Exemplo n.º 33
0
def test_split_no_split_occurred():
    x = plist([1, 2])
    left_list, right_list = x.split(2)
    assert left_list is x
    assert right_list is plist()
Exemplo n.º 34
0
def test_rest_return_self_on_empty_list():
    assert plist().rest is plist()
Exemplo n.º 35
0
def test_split_empty_list():
    left_list, right_list = plist().split(2)
    assert left_list == plist()
    assert right_list == plist()
Exemplo n.º 36
0
def test_literalish_works():
    assert l(1, 2, 3) == plist([1, 2, 3])
Exemplo n.º 37
0
def test_remove_missing_element():
    with pytest.raises(ValueError):
        plist([1, 2]).remove(3)

    with pytest.raises(ValueError):
        plist().remove(2)
Exemplo n.º 38
0
def test_reverse():
    assert plist([1, 2, 3]).reverse() == plist([3, 2, 1])
    assert reversed(plist([1, 2, 3])) == plist([3, 2, 1])

    assert plist().reverse() == plist()
    assert reversed(plist()) == plist()
Exemplo n.º 39
0
def test_supports_weakref():
    import weakref
    weakref.ref(plist())
    weakref.ref(plist([1, 2]))
Exemplo n.º 40
0
def test_inequality():
    assert plist([1, 2]) != plist([1, 3])
    assert plist([1, 2]) != plist([1, 2, 3])
    assert plist() != plist([1, 2, 3])
Exemplo n.º 41
0
def test_cons():
    assert plist([1, 2, 3]).cons(0) == plist([0, 1, 2, 3])
Exemplo n.º 42
0
def test_repr():
    assert str(plist()) == "plist([])"
    assert str(plist([1, 2, 3])) == "plist([1, 2, 3])"
Exemplo n.º 43
0
def test_truthiness():
    assert plist([1])
    assert not plist()
Exemplo n.º 44
0
def test_indexing():
    assert plist([1, 2, 3])[2] == 3
    assert plist([1, 2, 3])[-1] == 3
Exemplo n.º 45
0
def test_first_illegal_on_empty_list():
    with pytest.raises(AttributeError):
        plist().first
Exemplo n.º 46
0
def test_indexing_on_empty_list():
    with pytest.raises(IndexError):
        plist()[0]
Exemplo n.º 47
0
def test_literalish_works():
    assert l(1, 2, 3) == plist([1, 2, 3])
Exemplo n.º 48
0
def test_index_out_of_range():
    with pytest.raises(IndexError):
        plist([1, 2])[2]

    with pytest.raises(IndexError):
        plist([1, 2])[-3]
Exemplo n.º 49
0
def test_inequality():
    assert plist([1, 2]) != plist([1, 3])
    assert plist([1, 2]) != plist([1, 2, 3])
    assert plist() != plist([1, 2, 3])
Exemplo n.º 50
0
def test_index_invalid_type():
    with pytest.raises(TypeError) as e:
        plist([1, 2, 3])['foo']

    assert 'cannot be interpreted' in str(e)
Exemplo n.º 51
0
def test_indexing():
    assert plist([1, 2, 3])[2] == 3
    assert plist([1, 2, 3])[-1] == 3
Exemplo n.º 52
0
def test_first_and_rest():
    pl = plist([1, 2])
    assert pl.first == 1
    assert pl.rest.first == 2
    assert pl.rest.rest is plist()
Exemplo n.º 53
0
def test_index_out_of_range():
    with pytest.raises(IndexError):
        plist([1, 2])[2]

    with pytest.raises(IndexError):
        plist([1, 2])[-3]
Exemplo n.º 54
0
def test_hashing():
    assert hash(plist([1, 2])) == hash(plist([1, 2]))
    assert hash(plist([1, 2])) != hash(plist([2, 1]))
Exemplo n.º 55
0
def test_first_and_rest():
    pl = plist([1, 2])
    assert pl.first == 1
    assert pl.rest.first == 2
    assert pl.rest.rest is plist()
Exemplo n.º 56
0
def test_split():
    left_list, right_list = plist([1, 2, 3, 4, 5]).split(3)
    assert left_list == plist([1, 2, 3])
    assert right_list == plist([4, 5])
Exemplo n.º 57
0
def test_slicing_take_out_of_range():
    assert plist([1, 2, 3])[:20] == plist([1, 2, 3])
Exemplo n.º 58
0
def test_instantiate_large_list():
    assert plist(range(1000)).first == 0
Exemplo n.º 59
0
def test_slicing_take():
    assert plist([1, 2, 3])[:2] == plist([1, 2])
Exemplo n.º 60
0
def test_split():
    left_list, right_list = plist([1, 2, 3, 4, 5]).split(3)
    assert left_list == plist([1, 2, 3])
    assert right_list == plist([4, 5])