Files @ ae3e4617d31e
Branch filter:

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

Brett Smith
historical: Always format rates with the same precision.

When we format a rate as a price, we don't know how much precision
is "enough" to do the conversion, because we don't know what's
being converted to. As a result, we may (=will almost certainly)
end up formatting the rate with different precision on the cost
date vs. the price date, and that causes Beancount/Ledger to fail
to make the connection between them.

Using a constant of 6 is enough to make the current test for
"enough" precision pass, so just do that for now. This might need
further refinement in the future.
import datetime
import decimal
import io
import pathlib
import random

import pytest

from oxrlib import __main__ as oxrmain

decimal.setcontext(oxrmain.decimal_context())

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))