-
Notifications
You must be signed in to change notification settings - Fork 31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
pytest compatibility #134
Comments
SGTM
…On Sun, Nov 10, 2024 at 11:50 PM Andy S. Lou ***@***.***> wrote:
Hi,
In beancount v2 there is a handy utility to incorporate Importer unit
tests with pytest:
https://github.com/beancount/beancount/blob/v2/beancount/ingest/regression_pytest.py
I couldn't find the equivalent in beangulp. In the examples directory, I
saw the tests are driven by a bash script:
https://github.com/beancount/beangulp/blob/master/examples/importers/runtests.sh
Are you guys open to adding the pytest compatibility to beangulp, or
accepting PRs? Something along the lines of this:
import os
from typing import List, Optional, Union
import beangulp
import beangulp.testing
import click
import pytest
from beangulp import utils
from beangulp.importer import Importer, ImporterProtocol
def run_test_programmatically(
importer: Union[Importer, ImporterProtocol],
documents: List[str],
expected: Optional[str] = None,
verbose: int = 0,
quiet: int = 0,
failfast: bool = False,
generate: bool = False,
) -> None:
"""
Programmatically run the test command that would normally be invoked via CLI.
Args:
importer: The importer instance to test
documents: List of document paths to test
expected: A directory for expected output files
verbose: Verbosity level (default: 0)
quiet: Quiet level (default: 0)
failfast: Whether to stop at first failure (default: False)
generate: If True, then generates test data
"""
ctx_obj = beangulp.Ingest([importer])
command = beangulp.testing._generate if generate else beangulp.testing._test
with click.Context(command, obj=ctx_obj) as ctx:
if generate:
command.callback(documents=documents, expected=expected, verbose=verbose, quiet=quiet, force=True)
# Verify that the expected files were generated
for doc in utils.walk(documents):
if doc.endswith(".beancount"):
continue
expected_filename = f"{doc}.beancount"
if not os.path.exists(expected_filename):
raise FileNotFoundError(f"Did not generate expected file: {expected_filename}")
else:
command.callback(documents=documents, expected=expected, verbose=verbose, quiet=quiet, failfast=failfast)
Thanks,
Andy
—
Reply to this email directly, view it on GitHub
<#134>, or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AACSBE72UAMKPDGR5H63S5T2AAZRFAVCNFSM6AAAAABRRAM2K2VHI2DSMVQWIX3LMV43ASLTON2WKOZSGY2DQMJUHEYTKMQ>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi,
In beancount v2 there is a handy utility to incorporate Importer unit tests with pytest: https://github.com/beancount/beancount/blob/v2/beancount/ingest/regression_pytest.py
I couldn't find the equivalent in beangulp. In the examples directory, I saw the tests are driven by a bash script: https://github.com/beancount/beangulp/blob/master/examples/importers/runtests.sh
Are you guys open to adding the pytest compatibility to beangulp, or accepting PRs? Something along the lines of this:
Thanks,
Andy
The text was updated successfully, but these errors were encountered: