qc.csv¶
CsvTestSuite ¶
CsvTestSuite(data_stream: Csv)
Bases: Suite
Test suite to check if CSV files generated are well formatted.
Provides tests to validate that CSV files conform to expected formatting standards and contain valid data.
Attributes:
| Name | Type | Description |
|---|---|---|
data_stream |
The CSV data stream to test. |
Examples:
from contraqctor.contract.csv import Csv, CsvParams
from contraqctor.qc.csv import CsvTestSuite
from contraqctor.qc.base import Runner
# Create and load a CSV data stream
params = CsvParams(path="data/measurements.csv")
csv_stream = Csv("measurements", reader_params=params).load()
# Create and run the test suite
suite = CsvTestSuite(csv_stream)
runner = Runner().add_suite(suite)
results = runner.run_all_with_progress()
Initialize the CSV test suite.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data_stream
|
Csv
|
The CSV data stream to test. |
required |
Source code in src/contraqctor/qc/csv.py
33 34 35 36 37 38 39 | |
description
property
¶
name
property
¶
name: str
Get the name of the test suite.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The name of the test suite class. |
test_is_instance_of_pandas_dataframe ¶
test_is_instance_of_pandas_dataframe()
Check if the data stream is a pandas DataFrame.
Source code in src/contraqctor/qc/csv.py
41 42 43 44 45 46 47 48 49 | |
test_is_not_empty ¶
test_is_not_empty()
Check if the DataFrame is not empty.
Source code in src/contraqctor/qc/csv.py
51 52 53 54 55 56 57 58 | |
test_infer_missing_headers ¶
test_infer_missing_headers()
Infer if the DataFrame was loaded from a CSV without headers.
Source code in src/contraqctor/qc/csv.py
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 | |
get_tests ¶
Find all methods starting with 'test'.
Yields:
| Name | Type | Description |
|---|---|---|
ITest |
ITest
|
Test methods found in the suite. |
Source code in src/contraqctor/qc/base.py
350 351 352 353 354 355 356 357 358 | |
pass_test ¶
pass_test() -> Result
pass_test(
result: Any = None,
message: Optional[str] = None,
*,
context: Optional[Any] = None,
) -> Result
Create a passing test result.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
result
|
Any
|
The value to include in the test result. |
None
|
message
|
Optional[str]
|
Optional message describing why the test passed. |
None
|
context
|
Optional[Any]
|
Optional contextual data for the test result. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Result |
Result
|
A Result object with PASSED status. |
Source code in src/contraqctor/qc/base.py
463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 | |
warn_test ¶
warn_test() -> Result
warn_test(
result: Any = None,
message: Optional[str] = None,
*,
context: Optional[Any] = None,
) -> Result
Create a warning test result.
Creates a result with WARNING status, or FAILED if warnings are elevated.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
result
|
Any
|
The value to include in the test result. |
None
|
message
|
Optional[str]
|
Optional message describing the warning. |
None
|
context
|
Optional[Any]
|
Optional contextual data for the test result. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Result |
Result
|
A Result object with WARNING or FAILED status. |
Source code in src/contraqctor/qc/base.py
554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 | |
fail_test ¶
fail_test() -> Result
fail_test(
result: Optional[Any] = None,
message: Optional[str] = None,
*,
context: Optional[Any] = None,
) -> Result
Create a failing test result.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
result
|
Optional[Any]
|
The value to include in the test result. |
None
|
message
|
Optional[str]
|
Optional message describing why the test failed. |
None
|
context
|
Optional[Any]
|
Optional contextual data for the test result. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Result |
Result
|
A Result object with FAILED status. |
Source code in src/contraqctor/qc/base.py
629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 | |
skip_test ¶
skip_test() -> Result
Create a skipped test result.
Creates a result with SKIPPED status, or FAILED if skips are elevated.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
Optional[str]
|
Optional message explaining why the test was skipped. |
None
|
context
|
Optional[Any]
|
Optional contextual data for the test result. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Result |
Result
|
A Result object with SKIPPED or FAILED status. |
Source code in src/contraqctor/qc/base.py
691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 | |
setup_suite ¶
setup_suite() -> None
Run once before any test method in the suite.
Mimics :meth:unittest.TestCase.setUpClass. Override this to perform
expensive or failure-prone preparation — e.g. loading a data stream's
.data — a single time for the whole suite, rather than in __init__
(which is not protected by exception handling) or in :meth:setup (which
re-runs before every test).
The :class:Runner invokes this inside an exception-handling block. If it
raises, every test in the suite is reported as an error instead of being
run, and :meth:teardown_suite is not called. Suite construction and
test discovery are unaffected.
Source code in src/contraqctor/qc/base.py
714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 | |
teardown_suite ¶
teardown_suite() -> None
Run once after all test methods in the suite have run.
Mimics :meth:unittest.TestCase.tearDownClass. Only invoked if
:meth:setup_suite completed successfully.
Source code in src/contraqctor/qc/base.py
730 731 732 733 734 735 736 | |
setup ¶
setup() -> None
Run before each test method.
Mimics :meth:unittest.TestCase.setUp. This method can be overridden by
subclasses to implement setup logic that runs before each test. For work
that should happen only once for the whole suite, override
:meth:setup_suite instead.
Source code in src/contraqctor/qc/base.py
738 739 740 741 742 743 744 745 746 | |
teardown ¶
teardown() -> None
Run after each test method.
Mimics :meth:unittest.TestCase.tearDown. This method can be overridden
by subclasses to implement teardown logic that runs after each test. For
work that should happen only once for the whole suite, override
:meth:teardown_suite instead.
Source code in src/contraqctor/qc/base.py
748 749 750 751 752 753 754 755 756 | |
run_test ¶
Run a single test method and yield its results.
Handles setup, test execution, result processing, and teardown.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
test_method
|
ITest
|
The test method to run. |
required |
Yields:
| Name | Type | Description |
|---|---|---|
Result |
Result
|
Result objects produced by the test method. |
Source code in src/contraqctor/qc/base.py
840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 | |
run_all ¶
Run all test methods in the suite.
Runs :meth:setup_suite once, then all test methods in sequence, then
:meth:teardown_suite. If :meth:setup_suite raises, every test is
yielded as an error result and no tests are run.
Yields:
| Name | Type | Description |
|---|---|---|
Result |
Result
|
Result objects produced by all test methods. |
Source code in src/contraqctor/qc/base.py
880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 | |