Skip to content

Commit

Permalink
test: Add test_sink test cases, exercising recently added properties (
Browse files Browse the repository at this point in the history
#54)

## About

- Add software tests missing from GH-50.
- Improve documentation wrt. GH-53.
  • Loading branch information
amotl authored Dec 19, 2023
1 parent 2b156b6 commit 99a41f3
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ coverage.xml
.hypothesis/
.pytest_cache/

# Test artefacts
*.csv

# Translations
*.mo
*.pot
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Built with the [Meltano SDK](https://sdk.meltano.com) for Singer Taps and Target

| Setting | Required | Default | Description |
|:-------------------------|:--------:|:-------:|:------------|
| output_path | False | None | Filesystem path where to store output files. By default, the current working directory will be used. |
| output_path | False | None | Filesystem path where to store output files. By default, the current working directory will be used. When specified, the output directory will be created automatically. |
| file_naming_scheme | False | {stream_name}.csv | The scheme with which output files will be named. Naming scheme may leverage any of the following substitutions:<BR/>- `{stream_name}`<BR/>- `{datestamp}`<BR/>- `{timestamp}` |
| datestamp_format | False | %Y-%m-%d | A python format string to use when outputting the `{datestamp}` string. For reference, see: https://docs.python.org/3/library/datetime.html#strftime-and-strptime-format-codes |
| timestamp_format | False | %Y-%m-%d.T%H%M%S | A python format string to use when outputting the `{timestamp}` string. For reference, see: https://docs.python.org/3/library/datetime.html#strftime-and-strptime-format-codes |
Expand Down
49 changes: 49 additions & 0 deletions tests/test_sink.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
from pathlib import Path

import pytest

from target_csv.sinks import CSVSink
from target_csv.target import TargetCSV


def test_sink_output_file_cwd():
"""Verify `output_file` property without defining an output path."""
target = TargetCSV()
sink = CSVSink(
target=target, stream_name="foo", schema={"properties": {}}, key_properties=[]
)
assert sink.output_file == Path("foo.csv")


@pytest.mark.parametrize(
"property_name", ["output_path", "destination_path", "output_path_prefix"]
)
def test_sink_output_file_with_path(tmp_path, property_name):
"""Verify `output_file` property when defining an output path.
The test is parameterized to iterate and verify all the possible properties
which define an output path.
"""
folder_path = tmp_path / "to/folder"
output_file = tmp_path / "to/folder/foo.csv"
target = TargetCSV(config={property_name: str(folder_path)})
sink = CSVSink(
target=target, stream_name="foo", schema={"properties": {}}, key_properties=[]
)
assert sink.output_file == output_file


def test_sink_output_file_with_path_deprecated(tmp_path):
"""Verify `output_file` property with deprecated `output_path_prefix` property."""
folder_path = tmp_path / "to/folder"
output_file = tmp_path / "to/folder/foo.csv"
target = TargetCSV(config={"output_path_prefix": str(folder_path)})
sink = CSVSink(
target=target, stream_name="foo", schema={"properties": {}}, key_properties=[]
)
with pytest.warns(
UserWarning,
match="The property `output_path_prefix` is deprecated, "
"please use `output_path`.",
):
assert sink.output_file == output_file

0 comments on commit 99a41f3

Please sign in to comment.