<commit_before># -*- encoding: utf-8 -*-
from . import FixtureTest


class MergeJunctionTest(FixtureTest):

    def test_junction(self):
        from tilequeue.tile import coord_to_bounds
        from shapely.geometry import LineString, asShape
        from ModestMaps.Core import Coordinate
        import dsl

        z, x, y = (12, 2048, 2048)

        minx, miny, maxx, maxy = coord_to_bounds(
            Coordinate(zoom=z, column=x, row=y))
        midx = 0.5 * (minx + maxx)
        midy = 0.5 * (miny + maxy)

        road_props = dict(
            highway='residential',
            source='openstreetmap.org',
        )

        # make a tile with 4 roads in an X shape, as below.
        #
        #  \    /
        #   1  2
        #    \/
        #    /\
        #   3  4
        #  /    \
        #
        # these should get merged into two lines 1->4 & 2->3.
        self.generate_fixtures(
            dsl.way(1, LineString([[minx, maxy], [midx, midy]]), road_props),
            dsl.way(2, LineString([[maxx, maxy], [midx, midy]]), road_props),
            dsl.way(3, LineString([[minx, miny], [midx, midy]]), road_props),
            dsl.way(4, LineString([[maxx, miny], [midx, midy]]), road_props),
        )

        with self.features_in_tile_layer(z, x, y, 'roads') as features:
            # should have merged into a single _feature_
            self.assertTrue(len(features) == 1)

            # the shape should be a multilinestring
            shape = asShape(features[0]['geometry'])
            self.assertTrue(shape.geom_type == 'MultiLineString')

            # with two internal linestrings
            self.assertTrue(len(shape.geoms) == 2)<commit_msg>Fix test for 'download mode' where features is empty.<commit_after># -*- encoding: utf-8 -*-
from . import FixtureTest


class MergeJunctionTest(FixtureTest):

    def test_junction(self):
        from tilequeue.tile import coord_to_bounds
        from shapely.geometry import LineString, asShape
        from ModestMaps.Core import Coordinate
        import dsl

        z, x, y = (12, 2048, 2048)

        minx, miny, maxx, maxy = coord_to_bounds(
            Coordinate(zoom=z, column=x, row=y))
        midx = 0.5 * (minx + maxx)
        midy = 0.5 * (miny + maxy)

        road_props = dict(
            highway='residential',
            source='openstreetmap.org',
        )

        # make a tile with 4 roads in an X shape, as below.
        #
        #  \    /
        #   1  2
        #    \/
        #    /\
        #   3  4
        #  /    \
        #
        # these should get merged into two lines 1->4 & 2->3.
        self.generate_fixtures(
            dsl.way(1, LineString([[minx, maxy], [midx, midy]]), road_props),
            dsl.way(2, LineString([[maxx, maxy], [midx, midy]]), road_props),
            dsl.way(3, LineString([[minx, miny], [midx, midy]]), road_props),
            dsl.way(4, LineString([[maxx, miny], [midx, midy]]), road_props),
        )

        with self.features_in_tile_layer(z, x, y, 'roads') as features:
            # should have merged into a single _feature_
            self.assertTrue(len(features) == 1)

            # when the test suite runs in "download only mode", an empty
            # set of features is passed into this block. the assertion
            # is shorted out, so we need this additional check which is
            # trivially satisfied in the case we're doing real testing.
            if len(features) == 1:
                # the shape should be a multilinestring
                shape = asShape(features[0]['geometry'])
                self.assertTrue(shape.geom_type == 'MultiLineString')

                # with two internal linestrings
                self.assertTrue(len(shape.geoms) == 2)
{'fraction_non_alphanumeric': 0.11584553928095873, 'fraction_numerical': 0.01677762982689747, 'mean_word_length': 1.8390022675736961, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5821951', 'n_tokens_mistral': 1221, 'n_tokens_neox': 1160, 'n_words': 317}