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
321 322 323 324 325 326 327 328 329 |
|
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
434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 |
|
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
525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 |
|
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
600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 |
|
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
662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 |
|
setup ¶
setup() -> None
Run before each test method.
This method can be overridden by subclasses to implement setup logic that runs before each test.
Source code in src/contraqctor/qc/base.py
685 686 687 688 689 690 691 |
|
teardown ¶
teardown() -> None
Run after each test method.
This method can be overridden by subclasses to implement teardown logic that runs after each test.
Source code in src/contraqctor/qc/base.py
693 694 695 696 697 698 699 |
|
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
745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 |
|
run_all ¶
Run all test methods in the suite.
Finds all test methods and runs them in sequence.
Yields:
Name | Type | Description |
---|---|---|
Result |
Result
|
Result objects produced by all test methods. |
Source code in src/contraqctor/qc/base.py
785 786 787 788 789 790 791 792 793 794 |
|