Skip to content

Commit 93ec9ac

Browse files
authored
Merge pull request #6 from JS2IIU-MH/copilot/refactor-test-fixture-usage
Use pytest tmp_path for temporary test outputs in tests/test_adiftools.py
2 parents cd65591 + 987778e commit 93ec9ac

1 file changed

Lines changed: 16 additions & 28 deletions

File tree

tests/test_adiftools.py

Lines changed: 16 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
import pytest
2-
import tempfile
3-
from pathlib import Path
4-
from typing import Any, Generator
52

63
from adiftools import adiftools
74

@@ -22,16 +19,6 @@ def prep_data():
2219
return df
2320

2421

25-
@pytest.fixture(scope='function')
26-
def txt_file() -> Generator[Path, Any, None]:
27-
''' csv tempfile '''
28-
path = Path(tempfile.NamedTemporaryFile(suffix='.txt', delete=False).name)
29-
yield path
30-
31-
# delete tempfile after test
32-
path.unlink()
33-
34-
3522
def test_read_adi(prep_data):
3623
''' test adif DataFrame '''
3724
assert prep_data.shape == (126, 14)
@@ -42,28 +29,32 @@ def test_read_adi(prep_data):
4229
'MY_GRIDSQUARE', 'COMMENT', 'GRIDSQUARE']
4330

4431

45-
def test_to_adi(prep_instance):
46-
prep_instance.to_adi('tests/sample_out.adi')
47-
assert True
32+
def test_to_adi(prep_instance, tmp_path):
33+
out = tmp_path / 'sample_out.adi'
34+
prep_instance.to_adi(str(out))
35+
assert out.exists()
4836

4937

50-
def test_plot_monthly(prep_instance):
51-
prep_instance.plot_monthly('tests/monthly_qso_test.png')
52-
assert True
38+
def test_plot_monthly(prep_instance, tmp_path):
39+
out = tmp_path / 'monthly_qso_test.png'
40+
prep_instance.plot_monthly(str(out))
41+
assert out.exists()
5342

5443

55-
def test_plot_band_percentage(prep_instance):
56-
prep_instance.plot_band_percentage('tests/percentage_band_test.png')
57-
assert True
44+
def test_plot_band_percentage(prep_instance, tmp_path):
45+
out = tmp_path / 'percentage_band_test.png'
46+
prep_instance.plot_band_percentage(str(out))
47+
assert out.exists()
5848

5949

6050
def test_number_of_records(prep_instance):
6151
assert prep_instance.number_of_records == 126
6252

6353

64-
def test_call_to_txt(prep_instance, txt_file):
65-
prep_instance.call_to_txt(txt_file)
66-
assert True
54+
def test_call_to_txt(prep_instance, tmp_path):
55+
out = tmp_path / 'calls.txt'
56+
prep_instance.call_to_txt(str(out))
57+
assert out.exists()
6758

6859

6960
@pytest.mark.parametrize(
@@ -205,6 +196,3 @@ def test_error_is_ja(callsign, expected):
205196
)
206197
def test_get_area_num(callsign, expected):
207198
assert expected == adiftools.get_area(callsign)
208-
209-
210-
# TODO: use test fixture to create a temporary file

0 commit comments

Comments
 (0)