<commit_before># -*- coding: utf-8 -*-

from __future__ import unicode_literals

import logging
import os
import shutil
from unittest import TestCase

import fiona

from centerline.io import create_centerlines

TESTS_DIR = os.path.dirname(os.path.abspath(__file__))
TMP_DIR = os.path.join(TESTS_DIR, 'tmp')
SHP_DIR = os.path.join(TESTS_DIR, 'data', 'shp')
GEOJSON_DIR = os.path.join(TESTS_DIR, 'data', 'geojson')


class TestCreateCenterlines(TestCase):

    def setUp(self):
        self.INPUT_SHP = os.path.join(SHP_DIR, 'polygons.shp')
        os.mkdir(TMP_DIR)

    def tearDown(self):
        if os.path.exists(TMP_DIR):
            shutil.rmtree(TMP_DIR)

    def test__shp_to_shp_execution_successful_returns_None(self):
        DST_SHP = os.path.join(TMP_DIR, 'centerlines.shp')

        output = create_centerlines(src=self.INPUT_SHP, dst=DST_SHP)
        self.assertIsNone(output)

    def test__shp_to_shp_too_big_density(self):
        DST_SHP = os.path.join(TMP_DIR, 'centerlines.shp')

        log_name = os.path.join(TMP_DIR, "logging.log")
        logging.basicConfig(filename=log_name)
        create_centerlines(src=self.INPUT_SHP, dst=DST_SHP, density=11)
        with open(log_name) as log:
            self.assertEqual(
                "WARNING:root:ignoring record " +
                "that could not be processed: " +
                "Number of produced ridges is too small: " +
                "0, this might be caused by too large " +
                "interpolation distance.",
                log.readlines()[0].strip(),
            )

    def test__shp_to_shp_records_geom_type_is_multilinestring(self):
        EXPECTED_TYPE = 'MultiLineString'

        DST_SHP = os.path.join(TMP_DIR, 'centerlines.shp')
        create_centerlines(src=self.INPUT_SHP, dst=DST_SHP)

        with fiona.open(DST_SHP) as dst:
            for record in dst:
                self.assertEqual(
                    record.get('geometry').get('type'),
                    EXPECTED_TYPE
                )

    def test__shp_to_shp_record_count_is_3(self):
        EXPECTED_COUNT = 3
<commit_msg>Fix test<commit_after># -*- coding: utf-8 -*-

from __future__ import unicode_literals

import logging
import os
import shutil
from unittest import TestCase

import fiona

from centerline.io import create_centerlines

TESTS_DIR = os.path.dirname(os.path.abspath(__file__))
TMP_DIR = os.path.join(TESTS_DIR, 'tmp')
SHP_DIR = os.path.join(TESTS_DIR, 'data', 'shp')
GEOJSON_DIR = os.path.join(TESTS_DIR, 'data', 'geojson')


class TestCreateCenterlines(TestCase):

    def setUp(self):
        self.INPUT_SHP = os.path.join(SHP_DIR, 'polygons.shp')
        os.mkdir(TMP_DIR)

    def tearDown(self):
        if os.path.exists(TMP_DIR):
            shutil.rmtree(TMP_DIR)

    def test__shp_to_shp_execution_successful_returns_None(self):
        DST_SHP = os.path.join(TMP_DIR, 'centerlines.shp')

        output = create_centerlines(src=self.INPUT_SHP, dst=DST_SHP)
        self.assertIsNone(output)

    def test__shp_to_shp_too_big_density(self):
        DST_SHP = os.path.join(TMP_DIR, 'centerlines.shp')
        saved_rows = []

        def fake_warning(s, arg=None):
            if arg is not None:
                s = s % arg
            saved_rows.append(s)

        orig_warning = logging.warning
        logging.warning = fake_warning
        create_centerlines(src=self.INPUT_SHP, dst=DST_SHP, density=11)
        self.assertEqual(
            saved_rows[0],
            "ignoring record that could not be processed: " +
            "Number of produced ridges is too small: " +
            "0, this might be caused by too large " +
            "interpolation distance.",
        )
        logging.warning = orig_warning

    def test__shp_to_shp_records_geom_type_is_multilinestring(self):
        EXPECTED_TYPE = 'MultiLineString'

        DST_SHP = os.path.join(TMP_DIR, 'centerlines.shp')
        create_centerlines(src=self.INPUT_SHP, dst=DST_SHP)

        with fiona.open(DST_SHP) as dst:
            for record in dst:
                self.assertEqual(
                    record.get('geometry').get('type'),
                    EXPECTED_TYPE
                )

    def test__shp_to_shp_record_count_is_3(self):
        EXPECTED_COUNT = 3

{'fraction_non_alphanumeric': 0.10044695365796283, 'fraction_numerical': 0.003293342742884027, 'mean_word_length': 2.5671140939597317, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3661432', 'n_tokens_mistral': 1462, 'n_tokens_neox': 1436, 'n_words': 260}