예제 #1
0
파일: base.py 프로젝트: lycantropos/locus
def to_boxes(scalars: Strategy[Scalar]) -> Strategy[Box]:
    return (to_pairs(strategies.lists(scalars,
                                      min_size=2,
                                      max_size=2,
                                      unique=True)
                     .map(sorted))
            .map(pack(add))
            .map(pack(Box)))
예제 #2
0
def to_boxes(context: Context,
             coordinates: Strategy[Scalar]) -> Strategy[Box]:
    return (to_pairs(strategies.lists(coordinates,
                                      unique=True,
                                      min_size=2,
                                      max_size=2)
                     .map(sorted))
            .map(pack(add))
            .map(pack(context.box_cls)))
예제 #3
0
def to_crossing_segments_pairs(context: Context,
                               coordinates: Strategy[Scalar]
                               ) -> Strategy[Tuple[Segment, Segment]]:
    segment_factory = pack(context.segment_cls)
    return (to_crossing_segments_pairs_endpoints(context, coordinates)
            .map(cleave(compose(segment_factory, itemgetter(0, 1)),
                        compose(segment_factory, itemgetter(2, 3)))))
예제 #4
0
def coordinates_to_ported_points_pairs_edges_pairs(
        coordinates: Strategy[Coordinate]
) -> Strategy[Tuple[PortedPoint, PortedPoint, PortedEdge, PortedEdge]]:
    edges = coordinates_to_ported_edges(coordinates)
    return (strategies.tuples(
            coordinates_to_sorted_ported_points_pairs(coordinates),
            strategies.tuples(edges, edges))
            .map(pack(add)))
예제 #5
0
파일: base.py 프로젝트: lycantropos/rei
def to_repeated_patterns(strategy: Strategy[str]) -> Strategy[str]:
    counts = strategies.integers(0, 10)
    templates = (strategies.sampled_from(['{}?', '{}*', '{}+'])
                 | counts.map('{{}}{{{{{},}}}}'.format)
                 | counts.map('{{}}{{{{{}}}}}'.format)
                 | (strategies.tuples(counts, counts).map(sort_pair).map(
                     pack('{{}}{{{{{},{}}}}}'.format))))

    def apply_template(template: str) -> Strategy[str]:
        return strategy.map(template.format)

    return templates.flatmap(apply_template)
예제 #6
0
from paradigm import catalog
from tests.strategies import (identifiers, to_homogeneous_tuples)
from tests.utils import pack

objects_paths = to_homogeneous_tuples(identifiers).map(pack(catalog.Path))
예제 #7
0
def points_to_degenerate_segments(
        points: Strategy[Point]) -> Strategy[Segment]:
    return (points.map(partial(repeat, times=2)).map(pack(Segment)))
예제 #8
0
from hypothesis import strategies

from tests.integration_tests.utils import (to_bound_with_ported_boxes_pair,
                                           to_bound_with_ported_points_pair)
from tests.strategies import coordinates
from tests.utils import (pack, to_pairs)

points_pairs = strategies.builds(to_bound_with_ported_points_pair, coordinates,
                                 coordinates)
points_pairs_pairs = to_pairs(points_pairs)
boxes_pairs = points_pairs_pairs.map(pack(to_bound_with_ported_boxes_pair))
예제 #9
0
from hypothesis import strategies

from tests.utils import (BoundSet,
                         pack)

objects = strategies.integers()
objects_lists = strategies.lists(objects)
sets = objects_lists.map(pack(BoundSet))
예제 #10
0
def coordinates_to_segments(
        coordinates: Strategy[Coordinate]) -> Strategy[Segment]:
    return (to_pairs(coordinates_to_points(coordinates)).filter(pack(ne)).map(
        pack(Segment)))
예제 #11
0
from hypothesis import strategies

from tests.utils import (BoundVector,
                         pack)

objects = strategies.integers()
objects_lists = strategies.lists(objects)
vectors = objects_lists.map(pack(BoundVector))
예제 #12
0
multipoints_sizes_pairs = to_sizes_pairs(MIN_MULTIPOINT_SIZE)
multipolygons_sizes_pairs = to_sizes_pairs(MIN_MULTIPOLYGON_SIZE, 5)
multisegments_sizes_pairs = to_sizes_pairs(MIN_MULTISEGMENT_SIZE)
polygon_holes_sizes_pairs = to_sizes_pairs(0, 5)
non_valid_concave_contours_sizes_pairs = to_non_valid_sizes_pairs(
    MinContourSize.CONCAVE)
non_valid_convex_contours_sizes_pairs = to_non_valid_sizes_pairs(
    MinContourSize.CONVEX)
invalid_concave_contours_sizes_pairs = to_invalid_sizes_pairs(
    MinContourSize.CONCAVE)
invalid_convex_contours_sizes_pairs = to_invalid_sizes_pairs(
    MinContourSize.CONVEX)
invalid_mix_components_sizes_pairs_triplets = ((strategies.permutations(
    [to_sizes_pairs(0),
     strategies.just((0, 0)),
     strategies.just((0, 0))]).flatmap(pack(strategies.tuples))))
invalid_multicontours_sizes_pairs = to_invalid_sizes_pairs(
    MIN_MULTICONTOUR_SIZE)
invalid_polygon_holes_sizes_pairs = to_invalid_sizes_pairs(0)
invalid_multipoints_sizes_pairs = to_invalid_sizes_pairs(MIN_MULTIPOINT_SIZE)
invalid_multipolygons_sizes_pairs = to_invalid_sizes_pairs(
    MIN_MULTIPOLYGON_SIZE)
invalid_mix_points_sizes_pairs = to_invalid_sizes_pairs(0)
invalid_mix_polygons_sizes_pairs = to_invalid_sizes_pairs(0)
invalid_mix_segments_sizes_pairs = to_invalid_sizes_pairs(0)
invalid_multisegments_sizes_pairs = to_invalid_sizes_pairs(
    MIN_MULTISEGMENT_SIZE)


def to_coordinates_strategies_with_limits_and_types(
    type_: Type[Scalar]
예제 #13
0
def coordinates_to_ported_y_nodes(coordinates: Strategy[Coordinate]
                                  ) -> Strategy[PortedYNode]:
    return (coordinates_to_ported_edges_with_nodes_pairs(coordinates)
            .map(pack(PortedYNode)))
예제 #14
0
def coordinates_to_ported_x_nodes(coordinates: Strategy[Coordinate]
                                  ) -> Strategy[PortedXNode]:
    return (coordinates_to_ported_points_with_nodes_pairs(coordinates)
            .map(pack(PortedXNode)))
예제 #15
0
def coordinates_to_ported_trapezoids(coordinates: Strategy[Coordinate]
                                     ) -> Strategy[PortedTrapezoid]:
    return (coordinates_to_ported_points_pairs_edges_pairs(coordinates)
            .map(pack(PortedTrapezoid)))
예제 #16
0
def coordinates_to_ported_edges(coordinates: Strategy[Coordinate]
                                ) -> Strategy[PortedEdge]:
    return (coordinates_to_sorted_ported_points_pairs(coordinates)
            .map(pack(PortedEdge)))
예제 #17
0
파일: base.py 프로젝트: lycantropos/locus
def to_segments(scalar: Strategy[Scalar]) -> Strategy[Segment]:
    return (strategies.lists(to_points(scalar),
                             min_size=2,
                             max_size=2,
                             unique=True)
            .map(pack(Segment)))
예제 #18
0
from operator import ne

from _seidel import (Edge, Point)
from hypothesis import strategies

from tests.strategies import (floats, to_pairs)
from tests.utils import (pack, sort_points)

points = strategies.builds(Point, floats, floats)
sorted_points = to_pairs(points).filter(pack(ne)).map(sort_points)
edges = sorted_points.map(pack(Edge))
예제 #19
0
from functools import partial

from hypothesis import strategies

from tests.port_tests.factories import scalars_to_ported_polygons
from tests.port_tests.hints import PortedPolygon
from tests.port_tests.utils import (ported_operations_types,
                                    to_non_overlapping_ported_polygons_pair)
from tests.strategies import scalars_strategies
from tests.utils import (identity, pack, to_pairs)

operations_types = ported_operations_types
empty_polygons = strategies.builds(PortedPolygon, strategies.builds(list))
polygons = scalars_strategies.flatmap(scalars_to_ported_polygons)
non_empty_polygons_strategies = (scalars_strategies.map(
    partial(scalars_to_ported_polygons, min_size=1)))
non_empty_polygons = non_empty_polygons_strategies.flatmap(identity)
polygons_pairs = (strategies.tuples(empty_polygons, non_empty_polygons)
                  | strategies.tuples(non_empty_polygons, empty_polygons)
                  | non_empty_polygons_strategies.flatmap(to_pairs).map(
                      pack(to_non_overlapping_ported_polygons_pair)))
예제 #20
0
non_empty_compounds_factories = (
        strategies.sampled_from([coordinates_to_multipoints,
                                 coordinates_to_segments])
        | indexables_factories)
non_empty_geometries_factories = (strategies.just(coordinates_to_points)
                                  | non_empty_compounds_factories)
compounds_factories = (strategies.just(to_constant(empty_compounds))
                       | non_empty_compounds_factories)
indexables = (strategies.builds(call, indexables_factories,
                                coordinates_strategies)
              .flatmap(identity))
indexables_with_non_empty_geometries = strategies.builds(
        call,
        (strategies.tuples(indexables_factories,
                           non_empty_geometries_factories)
         .map(pack(cleave_in_tuples))),
        coordinates_strategies).flatmap(identity)
non_empty_compounds_strategies = strategies.builds(
        call, non_empty_compounds_factories, coordinates_strategies)
non_empty_compounds = non_empty_compounds_strategies.flatmap(identity)
non_empty_compounds_pairs = non_empty_compounds_strategies.flatmap(to_pairs)
compounds = (strategies.builds(call, compounds_factories,
                               coordinates_strategies)
             .flatmap(identity))
rational_compounds = (strategies.builds(call, compounds_factories,
                                        rational_coordinates_strategies)
                      .flatmap(identity))
rational_non_empty_compounds_with_coordinates_pairs = (
    (strategies.builds(call,
                       non_empty_compounds_factories
                       .map(lambda factory: cleave_in_tuples(factory, identity,
예제 #21
0
from hypothesis import strategies

from tests.utils import (PortedSet, pack)

objects = strategies.integers()
objects_lists = strategies.lists(objects)
sets = objects_lists.map(pack(PortedSet))
예제 #22
0
def to_valid_length(parts: List[str], *, limit: int = 255) -> List[str]:
    result = []
    parts = iter(parts)
    while limit > 0:
        try:
            part = next(parts)
        except StopIteration:
            break
        part = part[:limit]
        result.append(part)
        limit -= len(part) + len(os.sep)
    return result


paths = strategies.lists(identifiers).map(to_valid_length).map(pack(Path))


def is_valid_source(string: str) -> bool:
    try:
        ast.parse(string)
    except (ValueError, SyntaxError):
        return False
    else:
        return True


keywords_lists = strategies.lists(strategies.sampled_from(keyword.kwlist))
invalid_source_lines = ((keywords_lists.map(' '.join)
                         | keywords_lists.map(';'.join)).filter(
                             negate(is_valid_source)))
예제 #23
0
from hypothesis import strategies

from tests.strategies import (floats, to_bound_with_ported_edges_pair,
                              to_bound_with_ported_points_pair, to_pairs)
from tests.utils import (are_endpoints_non_degenerate, pack, sort_endpoints)

points_pairs = strategies.builds(to_bound_with_ported_points_pair, floats,
                                 floats)
sorted_points_pairs_pairs = (to_pairs(points_pairs).filter(
    are_endpoints_non_degenerate).map(sort_endpoints))
edges_pairs = (sorted_points_pairs_pairs.map(
    pack(to_bound_with_ported_edges_pair)))
예제 #24
0
from operator import add

from hypothesis import strategies

from tests.strategies import (floats,
                              to_bound_with_ported_edges_pair,
                              to_bound_with_ported_leaves_pair,
                              to_bound_with_ported_points_pair,
                              to_bound_with_ported_trapezoids_pair,
                              to_pairs)
from tests.utils import (are_endpoints_non_degenerate,
                         pack,
                         sort_endpoints)

points_pairs = strategies.builds(to_bound_with_ported_points_pair, floats,
                                 floats)
sorted_points_pairs_pairs = (to_pairs(points_pairs)
                             .filter(are_endpoints_non_degenerate)
                             .map(sort_endpoints))
edges_pairs = (sorted_points_pairs_pairs
               .map(pack(to_bound_with_ported_edges_pair)))
trapezoids_pairs = (strategies.tuples(sorted_points_pairs_pairs,
                                      to_pairs(edges_pairs))
                    .map(pack(add))
                    .map(pack(to_bound_with_ported_trapezoids_pair)))
leaves_pairs = trapezoids_pairs.map(pack(to_bound_with_ported_leaves_pair))
예제 #25
0
from operator import add

from hypothesis import strategies

from tests.strategies import (floats, to_bound_with_ported_edges_pair,
                              to_bound_with_ported_points_pair,
                              to_bound_with_ported_trapezoids_pair, to_pairs)
from tests.utils import (are_endpoints_non_degenerate, pack, sort_endpoints)

points_pairs = strategies.builds(to_bound_with_ported_points_pair, floats,
                                 floats)
sorted_points_pairs_pairs = (to_pairs(points_pairs).filter(
    are_endpoints_non_degenerate).map(sort_endpoints))
edges_pairs = (sorted_points_pairs_pairs.map(
    pack(to_bound_with_ported_edges_pair)))
trapezoids_pairs = (strategies.tuples(
    sorted_points_pairs_pairs, to_pairs(edges_pairs)).map(pack(add)).map(
        pack(to_bound_with_ported_trapezoids_pair)))
예제 #26
0
def to_plain_signatures(
        *,
        parameters_names: Strategy[str] = identifiers,
        parameters_kinds: Strategy[Parameter.Kind],
        parameters_has_default_flags: Strategy[bool] = strategies.booleans(),
        min_size: int = 0,
        max_size: int) -> Strategy[Base]:
    if min_size < 0:
        raise ValueError('Min size '
                         'should not be negative, '
                         'but found {min_size}.'.format(min_size=min_size))
    if min_size > max_size:
        raise ValueError('Min size '
                         'should not be greater '
                         'than max size, '
                         'but found {min_size} > {max_size}.'.format(
                             min_size=min_size, max_size=max_size))

    empty = strategies.builds(Plain)
    if max_size == 0:
        return empty

    @strategies.composite
    def extend(
        draw: Map[Strategy[Domain], Domain],
        base: Strategy[Tuple[Parameter,
                             ...]]) -> Strategy[Tuple[Parameter, ...]]:
        precursors = draw(base)
        precursors_names = set(map(attrgetter('name'), precursors))
        precursors_kinds = to_parameters_by_kind(precursors)
        last_precursor = precursors[-1]

        def is_kind_valid(parameter: Parameter) -> bool:
            if parameter.kind not in (Parameter.positionals_kinds
                                      | Parameter.keywords_kinds):
                return not precursors_kinds[parameter.kind]
            return True

        def normalize(parameter: Parameter) -> Parameter:
            if parameter.kind in Parameter.positionals_kinds:
                if last_precursor.has_default and not parameter.has_default:
                    return Parameter(name=parameter.name,
                                     kind=parameter.kind,
                                     has_default=True)
            return parameter

        follower = draw(
            to_parameters(
                names=identifiers.filter(negate(
                    precursors_names.__contains__)),
                kinds=(parameters_kinds.filter(
                    partial(le, max(precursors_kinds)))),
                has_default_flags=parameters_has_default_flags).filter(
                    is_kind_valid).map(normalize))
        return precursors + (follower, )

    base_parameters = to_parameters(
        names=parameters_names,
        kinds=parameters_kinds,
        has_default_flags=parameters_has_default_flags)
    non_empty = (strategies.recursive(strategies.tuples(base_parameters),
                                      extend,
                                      max_leaves=max_size).map(pack(Plain)))
    if min_size == 0:
        return empty | non_empty
    return non_empty
예제 #27
0
def scalars_to_segments(scalars: Strategy[Scalar]) -> Strategy[Segment]:
    return (to_pairs(scalars_to_points(scalars)).filter(pack(ne)).map(
        pack(Segment)))
예제 #28
0
def to_overloaded_signatures(bases: Strategy[Base],
                             *,
                             min_size: int = 2,
                             max_size: int = None) -> Strategy[Base]:
    return (strategies.lists(bases, min_size=min_size,
                             max_size=max_size).map(pack(Overloaded)))
예제 #29
0
from operator import (add, ne)

from _seidel import (Edge, Leaf, Node, Point, Trapezoid, XNode, YNode)
from hypothesis import strategies

from tests.strategies import (floats, recursive, to_pairs)
from tests.utils import (Strategy, pack, sort_points)

points = strategies.builds(Point, floats, floats)
sorted_points_pairs = to_pairs(points).filter(pack(ne)).map(sort_points)
edges = sorted_points_pairs.map(pack(Edge))
trapezoids = (strategies.tuples(sorted_points_pairs, to_pairs(edges)).map(
    pack(add)).map(pack(Trapezoid)))
leaves = trapezoids.map(Leaf)


def to_nodes(nodes: Strategy[Node]) -> Strategy[Node]:
    return to_x_nodes(nodes) | to_y_nodes(nodes)


def to_x_nodes(nodes: Strategy[Node]) -> Strategy[YNode]:
    return strategies.builds(XNode, points, nodes, nodes)


def to_y_nodes(nodes: Strategy[Node]) -> Strategy[YNode]:
    return strategies.builds(YNode, edges, nodes, nodes)


nodes = recursive(leaves, to_nodes)
x_nodes = to_x_nodes(nodes)
예제 #30
0
파일: base.py 프로젝트: lycantropos/rei

unrepeated_patterns = strategies.recursive(
    exact_patterns | characters_lists
    | excluded_characters_lists, extend_patterns)


def to_repeated_patterns(strategy: Strategy[str]) -> Strategy[str]:
    counts = strategies.integers(0, 10)
    templates = (strategies.sampled_from(['{}?', '{}*', '{}+'])
                 | counts.map('{{}}{{{{{},}}}}'.format)
                 | counts.map('{{}}{{{{{}}}}}'.format)
                 | (strategies.tuples(counts, counts).map(sort_pair).map(
                     pack('{{}}{{{{{},{}}}}}'.format))))

    def apply_template(template: str) -> Strategy[str]:
        return strategy.map(template.format)

    return templates.flatmap(apply_template)


patterns = (unrepeated_patterns
            | to_repeated_patterns(unrepeated_patterns.filter(bool)))
patterns |= strategies.tuples(patterns, patterns).map(pack('{}|{}'.format))
captures_names = strategies.text(strategies.sampled_from(string.ascii_letters),
                                 min_size=1)
patterns |= (strategies.tuples(captures_names,
                               patterns).map(pack('(?P<{}>{})'.format)))
patterns |= patterns.map('^{}'.format)
patterns |= patterns.map('{}$'.format)