Files @ 3b732505fa62
Branch filter:

Location: NPO-Accounting/oxrlib/tests/__init__.py

Brett Smith
main: Decimal context sets the state of all traps.

This commit started because I noticed in the decimal documentation that
BasicContext doesn't trap decimal.Subnormal, while oxrlib probably should.
The point of this function is to set all the parts of a context that oxrlib
should have to handle currency correctly and safely. With that motivation,
it makes more sense to set all the traps exactly as we want them, rather
than selectively setting "important" ones: they're all important.
import datetime
import io
import pathlib
import random

import pytest

TEST_DIR = pathlib.Path(__file__).parent

class StringIO(io.StringIO):
    def close(self):
        self.last_value = self.getvalue()
        super().close()

def relpath(*parts):
    return TEST_DIR / pathlib.Path(*parts)

@pytest.fixture
def any_date():
    return datetime.date.today() - datetime.timedelta(days=730 - random.randint(0, 365))