Skip to content

Commit

Permalink
Make near a top-level function
Browse files Browse the repository at this point in the history
  • Loading branch information
numberoverzero committed Jun 5, 2016
1 parent 5a14108 commit 3f3a4c5
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 4 deletions.
18 changes: 15 additions & 3 deletions roughly/__init__.py
@@ -1,5 +1,17 @@
import arrow
from .core import Mode
from . import _arrow as arrow
from . import _arrow

__version__ = "0.0.2"
__all__ = ["Mode", "arrow"]
__version__ = "0.0.3"
__all__ = ["Mode", "near"]


def near(obj, *args, **kwargs):
if isinstance(obj, arrow.Arrow):
if args:
raise ValueError("near(arrow.Arrow) only takes one datetime")
return _arrow.near(obj, **kwargs)
else:
raise NotImplementedError(
"roughly is still under development - make a request!"
" https://github.com/numberoverzero/roughly/issues/new")
2 changes: 1 addition & 1 deletion roughly/_arrow.py
Expand Up @@ -53,7 +53,7 @@ def __eq__(self, other):
raise RuntimeError("Unknown approximation mode {}".format(mode))


def near(arrow, **kwargs):
def near(arrow, *args, **kwargs):
return _approximate(arrow, Mode.Within, **kwargs)


Expand Down
24 changes: 24 additions & 0 deletions tests/test_roughly.py
@@ -0,0 +1,24 @@
import arrow
import pytest
from roughly import near


def test_near_arrow():
now = arrow.now()
not_now = now.replace(seconds=1)
roughly_now = near(not_now, seconds=5)
assert roughly_now == now


def test_near_arrow_args():
"""_arrow.near only takes one positional arg"""
with pytest.raises(ValueError):
near(arrow.now(), "extra posarg")


def test_not_implemented():
obj = object()
with pytest.raises(NotImplementedError) as excinfo:
near(obj)
new_issue_url = "https://github.com/numberoverzero/roughly/issues/new"
assert new_issue_url in str(excinfo.value)

0 comments on commit 3f3a4c5

Please sign in to comment.