Skip to content

Commit

Permalink
Tidy up test data and associated documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
lmarsden committed Mar 1, 2021
1 parent 5b95bc2 commit 3dfeec3
Show file tree
Hide file tree
Showing 9 changed files with 114 additions and 150 deletions.
4 changes: 2 additions & 2 deletions tests/gsfpy/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class GsfDatafile:
GsfVersion.V03_06,
Path(__file__).parent.parent
/ "test_data" # noqa: W503
/ "0029_20160323_185603_EX1604_MB.gsf.mb121", # noqa: W503
/ "GSF3_08_test_file.gsf", # noqa: W503
num_beams=432,
)

Expand All @@ -47,7 +47,7 @@ def _setup_gsf_test_data(src_datafile: GsfDatafile, tmp_path: Path):


@pytest.fixture
def gsf_test_data_03_06(tmp_path):
def gsf_test_data_03_08(tmp_path):
yield from _setup_gsf_test_data(GSF_03_06_DATAFILE, tmp_path)


Expand Down
32 changes: 16 additions & 16 deletions tests/gsfpy/test_gsffile.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,34 +7,34 @@
from gsfpy import *


def test_open_gsf_success(gsf_test_data_03_06):
def test_open_gsf_success(gsf_test_data_03_08):
"""
Open the test GSF file, then close.
"""
# Act
with open_gsf(gsf_test_data_03_06.path) as _:
with open_gsf(gsf_test_data_03_08.path) as _:
pass


def test_open_gsf_buffered_success(gsf_test_data_03_06):
def test_open_gsf_buffered_success(gsf_test_data_03_08):
"""
Open the test GSF file in buffered mode, then close.
"""
# Act
with open_gsf(gsf_test_data_03_06.path, buffer_size=100) as _:
with open_gsf(gsf_test_data_03_08.path, buffer_size=100) as _:
pass


def test_seek_success(gsf_test_data_03_06):
def test_seek_success(gsf_test_data_03_08):
"""
Open the test GSF file, seek to end of file, then close.
"""
# Act
with open_gsf(gsf_test_data_03_06.path) as gsf_file:
with open_gsf(gsf_test_data_03_08.path) as gsf_file:
gsf_file.seek(enums.SeekOption.GSF_END_OF_FILE)


def test_GsfException(gsf_test_data_03_06):
def test_GsfException(gsf_test_data_03_08):
"""
Try to open a non-existent GSF file, ensure a GsfException is raised and check
that it contains the correct error code and error message.
Expand All @@ -45,12 +45,12 @@ def test_GsfException(gsf_test_data_03_06):
).is_equal_to("[-1] GSF Unable to open requested file")


def test_read_success(gsf_test_data_03_06):
def test_read_success(gsf_test_data_03_08):
"""
Read a comment record from a GSF file.
"""
# Act
with open_gsf(gsf_test_data_03_06.path) as gsf_file:
with open_gsf(gsf_test_data_03_08.path) as gsf_file:
_, record = gsf_file.read(enums.RecordType.GSF_RECORD_COMMENT)

# Assert
Expand All @@ -63,12 +63,12 @@ def test_read_success(gsf_test_data_03_06):
)


def test_read_buffered_success(gsf_test_data_03_06):
def test_read_buffered_success(gsf_test_data_03_08):
"""
Read a comment record from a GSF file using a buffer.
"""
# Act
with open_gsf(gsf_test_data_03_06.path, buffer_size=1) as gsf_file:
with open_gsf(gsf_test_data_03_08.path, buffer_size=1) as gsf_file:
_, record = gsf_file.read(enums.RecordType.GSF_RECORD_COMMENT)

# Assert
Expand All @@ -81,7 +81,7 @@ def test_read_buffered_success(gsf_test_data_03_06):
)


def test_write_success(gsf_test_data_03_06):
def test_write_success(gsf_test_data_03_08):
"""
Write a single comment record to a new GSF file
"""
Expand Down Expand Up @@ -145,27 +145,27 @@ def test_direct_access_write_and_read_success(tmp_path):
assert_that(string_at(direct_access_record.comment.comment)).is_equal_to(comment_4)


def test_get_number_records_success(gsf_test_data_03_06):
def test_get_number_records_success(gsf_test_data_03_08):
"""
Open the test GSF file in GSF_READONLY_INDEX mode, count the number of
GSF_RECORD_SWATH_BATHYMETRY_PING records, then close.
"""
# Act
with open_gsf(gsf_test_data_03_06.path, FileMode.GSF_READONLY_INDEX) as gsf_file:
with open_gsf(gsf_test_data_03_08.path, FileMode.GSF_READONLY_INDEX) as gsf_file:
number_of_pings = gsf_file.get_number_records(
RecordType.GSF_RECORD_SWATH_BATHYMETRY_PING
)

assert_that(number_of_pings).is_equal_to(8)


def test_get_number_records_failure(gsf_test_data_03_06):
def test_get_number_records_failure(gsf_test_data_03_08):
"""
Open the test GSF file in GSF_READONLY mode, attempt to count the number of
GSF_RECORD_SWATH_BATHYMETRY_PING records and verify the exception.
"""
# Act
with open_gsf(gsf_test_data_03_06.path) as gsf_file:
with open_gsf(gsf_test_data_03_08.path) as gsf_file:
assert_that(gsf_file.get_number_records).raises(GsfException).when_called_with(
enums.RecordType.GSF_RECORD_SWATH_BATHYMETRY_PING
).is_equal_to("[-3] GSF Error illegal access mode")
Expand Down
57 changes: 7 additions & 50 deletions tests/gsfpy3_08/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@


class GsfVersion(Enum):
V03_06 = auto()
V03_07 = auto()
V03_08 = auto()


Expand All @@ -20,30 +18,12 @@ class GsfDatafile:
num_beams: int


GSF_03_06_DATAFILE = GsfDatafile(
GsfVersion.V03_06,
Path(__file__).parent.parent
/ "test_data" # noqa: W503
/ "0029_20160323_185603_EX1604_MB.gsf.mb121", # noqa: W503
GSF_03_08_DATAFILE = GsfDatafile(
GsfVersion.V03_08,
Path(__file__).parent.parent / "test_data" / "GSF3_08_test_file.gsf",
num_beams=432,
)

GSF_03_07_DATAFILE = GsfDatafile(
GsfVersion.V03_07,
Path(__file__).parent.parent
/ "test_data" # noqa: W503
/ "0059_20181102_212138_EX1811_MB_EM302.gsf.mb121", # noqa: W503
num_beams=432,
)

# GSF_03_08_DATAFILE = GsfDatafile(
# GsfVersion.V03_08,
# Path(__file__).parent.parent
# / "test_data"
# / "0059_20181102_212138_EX1811_MB_EM302.gsf.mb121",
# num_beams=432,
# )


def _setup_gsf_test_data(src_datafile: GsfDatafile, tmp_path: Path):
tmp_path.mkdir(parents=True, exist_ok=True)
Expand All @@ -56,37 +36,14 @@ def _setup_gsf_test_data(src_datafile: GsfDatafile, tmp_path: Path):


@pytest.fixture
def gsf_test_data_03_06(tmp_path):
yield from _setup_gsf_test_data(GSF_03_06_DATAFILE, tmp_path)

def gsf_test_data_03_08(tmp_path):
yield from _setup_gsf_test_data(GSF_03_08_DATAFILE, tmp_path)

@pytest.fixture
def gsf_test_data_03_07(tmp_path):
yield from _setup_gsf_test_data(GSF_03_07_DATAFILE, tmp_path)

fixture_union("gsf_test_data", [gsf_test_data_03_08])

# @pytest.fixture
# def gsf_test_data_03_08(tmp_path):
# yield from _setup_gsf_test_data(GSF_03_08_DATAFILE, tmp_path)


fixture_union(
"gsf_test_data",
[
gsf_test_data_03_06,
gsf_test_data_03_07,
# gsf_test_data_03_08,
],
)


@pytest.fixture(
params=[
GSF_03_06_DATAFILE,
GSF_03_07_DATAFILE,
# GSF_03_08_DATAFILE,
]
)
@pytest.fixture(params=[GSF_03_08_DATAFILE])
def gsf_test_data(request, tmp_path):
src_datafile: GsfDatafile = request.param
yield from _setup_gsf_test_data(src_datafile, tmp_path)
Loading

0 comments on commit 3dfeec3

Please sign in to comment.