-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
52 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from pymeos.range import RangeFloat as MEOSRangeFloat | ||
from sqlalchemy.types import UserDefinedType | ||
|
||
from .BaseType import BaseType | ||
|
||
|
||
class RangeFloat(BaseType): | ||
base_class = MEOSRangeFloat | ||
|
||
def get_col_spec(self): | ||
return "FLOATRANGE" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import datetime | ||
import pytest | ||
from pymeos.range import RangeFloat | ||
from sqlalchemy.exc import StatementError | ||
|
||
from .models import RangeFloats | ||
|
||
|
||
def test_simple_insert(session): | ||
rangefloat = RangeFloat(10, 20) | ||
|
||
session.add(RangeFloats(rangefloat=rangefloat)) | ||
session.commit() | ||
|
||
sql = session.query(RangeFloats).filter(RangeFloats.id == 1) | ||
assert sql.count() == 1 | ||
|
||
results = sql.all() | ||
for result in results: | ||
assert result.id == 1 | ||
assert str(result.rangefloat) == "[10, 20)" | ||
assert result.rangefloat.lower == 10 | ||
assert result.rangefloat.upper == 20 | ||
assert result.rangefloat.lower_inc == True | ||
assert result.rangefloat.upper_inc == False | ||
|
||
|
||
def test_str_values_are_invalid(session): | ||
rangefloat = "[10, 20)" | ||
|
||
with pytest.raises(StatementError): | ||
session.add(RangeFloats(rangefloat=rangefloat)) | ||
session.commit() |