Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions benchmark.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from timeit import timeit, repeat
from timeit import repeat, timeit

from spans import *

Expand Down Expand Up @@ -28,10 +28,13 @@ def run_benchmark(func, number=None):

total_time = sum(repeat(func, repeat=3, number=number)) / 3

print("{func:.<40} {loops} loops, best of 3: {per_loop} per loop".format(
func=func.__name__ + " ",
loops=number,
per_loop=format_sec(total_time / float(number))))
print(
"{func:.<40} {loops} loops, best of 3: {per_loop} per loop".format(
func=func.__name__ + " ",
loops=number,
per_loop=format_sec(total_time / float(number)),
)
)


# Create ranges here to prevent __init__ from affecting test results
Expand Down
14 changes: 7 additions & 7 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@

# -- Project information -----------------------------------------------------

project = 'Spans'
copyright = '2022, Andreas Runfalk'
author = 'Andreas Runfalk'
project = "Spans"
copyright = "2022, Andreas Runfalk"
author = "Andreas Runfalk"


# -- General configuration ---------------------------------------------------
Expand All @@ -33,22 +33,22 @@
]

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
templates_path = ["_templates"]

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path.
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]


# -- Options for HTML output -------------------------------------------------

# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
html_theme = 'alabaster'
html_theme = "alabaster"

# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']
html_static_path = ["_static"]
6 changes: 4 additions & 2 deletions doc/conftest.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import spans
from datetime import date, datetime, timedelta

import pytest

from datetime import date, datetime, timedelta
import spans


@pytest.fixture(autouse=True)
def doctest_fixture(doctest_namespace):
Expand Down
6 changes: 3 additions & 3 deletions spans/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
This module provides one dimensional continuous set support for python.

Python has a wonderful set class, it does however not handle continuous sets
between two endpoints. This module tries to mitigate that. The ranges' behavoir
between two endpoints. This module tries to mitigate that. The ranges' behavior
are modeled after PostgresSQL 9.2's range types. Deviating from PostgresSQL's
behavoir is considered a bug.
behavior is considered a bug.

In addition to the range types there are range sets. A range set is can be viewed
as a mutable list of ranges. A set enables discontinious chunks to be grouped
as a mutable list of ranges. A set enables discontinuous chunks to be grouped
together.
"""

Expand Down
2 changes: 1 addition & 1 deletion spans/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def __init__(self, lower=None, upper=None, lower_inc=None, upper_inc=None):

if upper is not None and not isinstance(upper, self.type):
raise TypeError(
f"Invalid type for lower bound '{upper.__class__.__name__}'"
f"Invalid type for upper bound '{upper.__class__.__name__}'"
f" expected '{self.type.__name__}'"
)

Expand Down
5 changes: 5 additions & 0 deletions tests/test_range.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ def test_invalid_construction(range_type, lower, upper, lower_inc, upper_inc, ex
range_type(lower, upper, lower_inc, upper_inc)


def test_invalid_upper_bound_message():
with pytest.raises(TypeError, match="upper bound"):
intrange(1, 1.5)


@pytest.mark.parametrize(
"range_type, lower, upper",
[
Expand Down