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

from geoalchemy2.shape import from_shape
from shapely.geometry import Polygon, MultiPolygon

from skylines.model import TimeZone


@pytest.fixture
def berlin(db_session):
    shape = MultiPolygon([Polygon(((30, 10), (40, 40), (20, 40), (10, 20), (30, 10)))])

    tz = TimeZone(tzid='Europe/Berlin', the_geom=from_shape(shape, srid=4326))
    db_session.add(tz)
    db_session.commit()
    return tz


def test_repr(berlin):
    assert repr(berlin) == '<TimeZone: tzid=\'Europe/Berlin\'>'
    assert isinstance(repr(berlin), str)
<commit_msg>model/timezone: Add `by_location()` tests<commit_after># -*- coding: utf-8 -*-
import pytest

from geoalchemy2.shape import from_shape
from shapely.geometry import Polygon, MultiPolygon

from skylines.model import TimeZone, Location


@pytest.fixture
def berlin(db_session):
    # |
    # |   *   *
    # |
    # | *
    # |     *
    # +------------
    shape = MultiPolygon([Polygon(((30, 10), (40, 40), (20, 40), (10, 20), (30, 10)))])

    tz = TimeZone(tzid='Europe/Berlin', the_geom=from_shape(shape, srid=4326))
    db_session.add(tz)
    db_session.commit()
    return tz


def test_repr(berlin):
    assert repr(berlin) == '<TimeZone: tzid=\'Europe/Berlin\'>'
    assert isinstance(repr(berlin), str)


@pytest.mark.usefixtures('berlin')
def test_by_location_returns_timezone():
    tz = TimeZone.by_location(Location(longitude=20, latitude=30))
    assert tz is not None
    assert tz.zone == 'Europe/Berlin'


@pytest.mark.usefixtures('berlin')
def test_by_location_returns_none_by_default():
    assert TimeZone.by_location(Location(longitude=10, latitude=10)) is None

{'fraction_non_alphanumeric': 0.15503875968992248, 'fraction_numerical': 0.03577817531305903, 'mean_word_length': 4.147239263803681, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '334177', 'n_tokens_mistral': 660, 'n_tokens_neox': 603, 'n_words': 124}