Skip to content

Commit

Permalink
Made PartialOrderingMixin use __slots___ (fixes #10)
Browse files Browse the repository at this point in the history
  • Loading branch information
runfalk committed Oct 25, 2017
1 parent 7e35440 commit 722de52
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 3 deletions.
2 changes: 2 additions & 0 deletions spans/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ def __setstate__(self, data):


class PartialOrderingMixin(object):
__slots__ = ()

def __le__(self, other):
lt = self.__lt__(other)
eq = self.__eq__(other)
Expand Down
24 changes: 23 additions & 1 deletion tests/test_range.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import pickle
import pytest

from spans import floatrange, intrange
from spans import \
daterange, datetimerange, floatrange, intrange, PeriodRange, strrange, \
timedeltarange


def test_empty():
Expand Down Expand Up @@ -523,3 +525,23 @@ def test_pickling():

def test_bug7_overlap_empty():
assert not intrange(1, 10).overlap(intrange.empty())


@pytest.mark.parametrize("cls", [
daterange,
datetimerange,
intrange,
floatrange,
PeriodRange,
strrange,
timedeltarange,
])
def test_bug10_missing_slots_in_cls_hierarchy(cls):
"""
`Bug #10 <https://github.com/runfalk/spans/issues/10>`_
"""

for c in cls.mro():
if c is object:
continue
assert hasattr(c, "__slots__")
25 changes: 23 additions & 2 deletions tests/test_rangeset.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import pickle
import pytest

from spans import floatrange, floatrangeset, intrange, intrangeset
from spans import \
daterangeset, datetimerangeset, floatrange, floatrangeset, intrange, \
intrangeset, strrangeset, timedeltarangeset


def test_empty():
Expand Down Expand Up @@ -216,7 +218,26 @@ def test_bug3_intersection():

def test_bug4_empty_set_iteration():
"""
`Bug #4 <https://github.com/runfalk/spans/issues/4>`
`Bug #4 <https://github.com/runfalk/spans/issues/4>`_
"""

assert list(intrangeset([])) == []


@pytest.mark.parametrize("cls", [
daterangeset,
datetimerangeset,
intrangeset,
floatrangeset,
strrangeset,
timedeltarangeset,
])
def test_bug10_missing_slots_in_cls_hierarchy(cls):
"""
`Bug #10 <https://github.com/runfalk/spans/issues/10`_
"""

for c in cls.mro():
if c is object:
continue
assert hasattr(c, "__slots__")

0 comments on commit 722de52

Please sign in to comment.