<commit_before>"""Tests for interval."""
from datetime import date, datetime, timedelta, timezone

import pytest

from interval import (
	Month,
	Week,
	Day,
	ProperInterval,
	FixedInterval,
	Interval,
	)


def test_interval_init():
	i = Interval(datetime(2017, 3, 22), datetime(2017, 3, 24))
	assert i.delta == timedelta(days=2)
	assert i == Interval(datetime(2017, 3, 22), delta=timedelta(days=2))
	assert i == Interval(end=datetime(2017, 3, 24), delta=timedelta(days=2))


def test_interval_init_tzinfo_mismatch():
	with pytest.raises(TypeError):
		Interval(datetime(2017, 3, 22), datetime.now(tz=timezone.utc))


def test_interval_init_value_mismatch():
	with pytest.raises(ValueError):
		Interval(datetime(2017, 3, 22), datetime(2017, 3, 24), timedelta(days=1))


def test_interval_init_only_beg():
	with pytest.raises(ValueError):
		Interval(datetime(2017, 3, 22))


def test_interval_init_only_end():
	with pytest.raises(ValueError):
		Interval(end=datetime(2017, 3, 22))


def test_interval_init_only_delta():
	with pytest.raises(ValueError):
		Interval(delta=timedelta(days=2))


def test_interval_init_empty():
	with pytest.raises(ValueError):
		Interval()


def test_tzinfo():
	assert Interval(datetime.now(timezone.utc), delta=timedelta(days=1)).tzinfo == timezone.utc


def test_tzinfo_from_end():
	assert Interval(end=datetime.now(timezone.utc), delta=timedelta(days=2)).tzinfo == timezone.utc


def test_str():
	i = Interval(datetime(2017, 3, 22), datetime(2017, 3, 24))<commit_msg>Don't use datetime.timezone, it didn't exist earlier.<commit_after>"""Tests for interval."""
from datetime import date, datetime, timedelta, tzinfo

import pytest

from interval import (
	Month,
	Week,
	Day,
	ProperInterval,
	FixedInterval,
	Interval,
	)


class UTCType(tzinfo):

	def utcoffset(self, dt):
		return timedelta(0)

	def tzname(self, dt):
		return "UTC"

	def dst(self, dt):
		return timedelta(0)


UTC = UTCType()


def test_interval_init():
	i = Interval(datetime(2017, 3, 22), datetime(2017, 3, 24))
	assert i.delta == timedelta(days=2)
	assert i == Interval(datetime(2017, 3, 22), delta=timedelta(days=2))
	assert i == Interval(end=datetime(2017, 3, 24), delta=timedelta(days=2))


def test_interval_init_tzinfo_mismatch():
	with pytest.raises(TypeError):
		Interval(datetime(2017, 3, 22), datetime.now(tz=UTC))


def test_interval_init_value_mismatch():
	with pytest.raises(ValueError):
		Interval(datetime(2017, 3, 22), datetime(2017, 3, 24), timedelta(days=1))


def test_interval_init_only_beg():
	with pytest.raises(ValueError):
		Interval(datetime(2017, 3, 22))


def test_interval_init_only_end():
	with pytest.raises(ValueError):
		Interval(end=datetime(2017, 3, 22))


def test_interval_init_only_delta():
	with pytest.raises(ValueError):
		Interval(delta=timedelta(days=2))


def test_interval_init_empty():
	with pytest.raises(ValueError):
		Interval()


def test_tzinfo():
	assert Interval(datetime.now(UTC), delta=timedelta(days=1)).tzinfo == UTC


def test_tzinfo_from_end():
	assert Interval(end=datetime.now(UTC), delta=timedelta(days=2)).tzinfo == UTC


def test_str():
	i = Interval(datetime(2017, 3, 22), datetime(2017, 3, 24))
{'fraction_non_alphanumeric': 0.14109459031951915, 'fraction_numerical': 0.05378044922492882, 'mean_word_length': 6.564593301435407, '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': '3642782', 'n_tokens_mistral': 1318, 'n_tokens_neox': 1147, 'n_words': 242}