Skip to content

Commit

Permalink
Refs #21325: Apply suggestions
Browse files Browse the repository at this point in the history
Signed-off-by: eduponz <[email protected]>
  • Loading branch information
EduPonz authored and richiware committed Jul 23, 2024
1 parent 0fe0d15 commit 6bcf74c
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 112 deletions.
1 change: 0 additions & 1 deletion fastdds_python/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ add_test(NAME api_tests
${Python3_EXECUTABLE}
-m pytest
-vrP
--cdr v2
WORKING_DIRECTORY
${CMAKE_CURRENT_SOURCE_DIR}/api
)
3 changes: 0 additions & 3 deletions fastdds_python/test/api/conftest.py

This file was deleted.

176 changes: 68 additions & 108 deletions fastdds_python/test/api/test_datareader.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@ class DataReaderListener (fastdds.DataReaderListener):
def __init__(self):
super().__init__()

@pytest.fixture
def cdr_version(request):
return request.config.getoption('--cdr')

@pytest.fixture(params=['no_module', 'module'], autouse=True)
def data_type(request):
if request.param == 'no_module':
Expand Down Expand Up @@ -112,8 +108,7 @@ def datawriter(writer_participant, writer_topic, publisher):
factory.delete_participant(writer_participant))


# This function should be used in a test which uses 'cdr_version' fixture
def fill_keyed_complete_test_type(data, cdr_version):
def fill_keyed_complete_test_type(data):
# Auxiliary StructTypes
struct_type1 = pytest.dds_type.StructType()
struct_type1.char_field('\x01')
Expand Down Expand Up @@ -186,34 +181,19 @@ def fill_keyed_complete_test_type(data, cdr_version):
data.struct_field().string_field("Test string")
data.struct_field().enum_field(pytest.dds_type.Color_MAGENTA)
data.struct_field().enum2_field(pytest.dds_type.Material_METAL)
if (cdr_version == 'v1'):
data.char_opt_field('\x01')
data.uint8_opt_field(254)
data.int16_opt_field(-10)
data.uint16_opt_field(10)
data.int32_opt_field(-1000)
data.uint32_opt_field(1000)
data.int64_opt_field(-36000)
data.uint64_opt_field(36000)
data.float_opt_field(1.0)
data.double_opt_field(1202.5)
data.bool_opt_field(True)
data.string_opt_field("Test string")
data.enum_opt_field(pytest.dds_type.Color_MAGENTA)
else:
data.char_opt_field().set_value('\x01')
data.uint8_opt_field().set_value(254)
data.int16_opt_field().set_value(-10)
data.uint16_opt_field().set_value(10)
data.int32_opt_field().set_value(-1000)
data.uint32_opt_field().set_value(1000)
data.int64_opt_field().set_value(-36000)
data.uint64_opt_field().set_value(36000)
data.float_opt_field().set_value(1.0)
data.double_opt_field().set_value(1202.5)
data.bool_opt_field().set_value(True)
data.string_opt_field().set_value("Test string")
data.enum_opt_field().set_value(pytest.dds_type.Color_MAGENTA)
data.char_opt_field().set_value('\x01')
data.uint8_opt_field().set_value(254)
data.int16_opt_field().set_value(-10)
data.uint16_opt_field().set_value(10)
data.int32_opt_field().set_value(-1000)
data.uint32_opt_field().set_value(1000)
data.int64_opt_field().set_value(-36000)
data.uint64_opt_field().set_value(36000)
data.float_opt_field().set_value(1.0)
data.double_opt_field().set_value(1202.5)
data.bool_opt_field().set_value(True)
data.string_opt_field().set_value("Test string")
data.enum_opt_field().set_value(pytest.dds_type.Color_MAGENTA)
struct_field = pytest.dds_type.StructType()
struct_field.char_field('\x01')
struct_field.uint8_field(254)
Expand All @@ -229,10 +209,7 @@ def fill_keyed_complete_test_type(data, cdr_version):
struct_field.string_field("Test string")
struct_field.enum_field(pytest.dds_type.Color_MAGENTA)
struct_field.enum2_field(pytest.dds_type.Material_METAL)
if (cdr_version == 'v1'):
data.struct_opt_field(struct_field)
else:
data.struct_opt_field().set_value(struct_field)
data.struct_opt_field().set_value(struct_field)
data.array_char_field(['\x01', '\x02', '\x03'])
data.array_uint8_field([254, 255, 1])
data.array_int16_field([-10, 10, -20])
Expand Down Expand Up @@ -283,8 +260,7 @@ def fill_keyed_complete_test_type(data, cdr_version):
data.unbounded_sequence_struct_field([struct_type1, struct_type2, struct_type3])


# This function should be used in a test which uses 'cdr_version' fixture
def check_keyed_complete_test_type(data, cdr_version):
def check_keyed_complete_test_type(data):
assert(data.char_field() == '\x01')
assert(data.uint8_field() == 254)
assert(data.int16_field() == -10)
Expand Down Expand Up @@ -313,49 +289,34 @@ def check_keyed_complete_test_type(data, cdr_version):
assert(data.struct_field().string_field() == "Test string")
assert(data.struct_field().enum_field() == pytest.dds_type.Color_MAGENTA)
assert(data.struct_field().enum2_field() == pytest.dds_type.Material_METAL)
if cdr_version == 'v1':
assert(data.char_opt_field() == '\x01')
assert(data.uint8_opt_field() == 254)
assert(data.int16_opt_field() == -10)
assert(data.uint16_opt_field() == 10)
assert(data.int32_opt_field() == -1000)
assert(data.uint32_opt_field() == 1000)
assert(data.int64_opt_field() == -36000)
assert(data.uint64_opt_field() == 36000)
assert(data.float_opt_field() == 1.0)
assert(data.double_opt_field() == 1202.5)
assert(data.bool_opt_field() == True)
assert(data.string_opt_field() == "Test string")
assert(data.enum_opt_field() == pytest.dds_type.Color_MAGENTA)
else:
assert(data.char_opt_field().has_value())
assert(data.char_opt_field().get_value() == '\x01')
assert(data.uint8_opt_field().has_value())
assert(data.uint8_opt_field().get_value() == 254)
assert(data.int16_opt_field().has_value())
assert(data.int16_opt_field().get_value() == -10)
assert(data.uint16_opt_field().has_value())
assert(data.uint16_opt_field().get_value() == 10)
assert(data.int32_opt_field().has_value())
assert(data.int32_opt_field().get_value() == -1000)
assert(data.uint32_opt_field().has_value())
assert(data.uint32_opt_field().get_value() == 1000)
assert(data.int64_opt_field().has_value())
assert(data.int64_opt_field().get_value() == -36000)
assert(data.uint64_opt_field().has_value())
assert(data.uint64_opt_field().get_value() == 36000)
assert(data.float_opt_field().has_value())
assert(data.float_opt_field().get_value() == 1.0)
assert(data.double_opt_field().has_value())
assert(data.double_opt_field().get_value() == 1202.5)
assert(data.bool_opt_field().has_value())
assert(data.bool_opt_field().get_value() == True)
assert(data.string_opt_field().has_value())
assert(data.string_opt_field().get_value() == "Test string")
assert(data.enum_opt_field().has_value())
assert(data.enum_opt_field().get_value() == pytest.dds_type.Color_MAGENTA)
assert(not data.enum2_opt_field().has_value())
assert(data.struct_opt_field().has_value())
assert(data.char_opt_field().has_value())
assert(data.char_opt_field().get_value() == '\x01')
assert(data.uint8_opt_field().has_value())
assert(data.uint8_opt_field().get_value() == 254)
assert(data.int16_opt_field().has_value())
assert(data.int16_opt_field().get_value() == -10)
assert(data.uint16_opt_field().has_value())
assert(data.uint16_opt_field().get_value() == 10)
assert(data.int32_opt_field().has_value())
assert(data.int32_opt_field().get_value() == -1000)
assert(data.uint32_opt_field().has_value())
assert(data.uint32_opt_field().get_value() == 1000)
assert(data.int64_opt_field().has_value())
assert(data.int64_opt_field().get_value() == -36000)
assert(data.uint64_opt_field().has_value())
assert(data.uint64_opt_field().get_value() == 36000)
assert(data.float_opt_field().has_value())
assert(data.float_opt_field().get_value() == 1.0)
assert(data.double_opt_field().has_value())
assert(data.double_opt_field().get_value() == 1202.5)
assert(data.bool_opt_field().has_value())
assert(data.bool_opt_field().get_value() == True)
assert(data.string_opt_field().has_value())
assert(data.string_opt_field().get_value() == "Test string")
assert(data.enum_opt_field().has_value())
assert(data.enum_opt_field().get_value() == pytest.dds_type.Color_MAGENTA)
assert(not data.enum2_opt_field().has_value())
assert(data.struct_opt_field().has_value())
assert(data.struct_opt_field().char_field() == '\x01')
assert(data.struct_opt_field().uint8_field() == 254)
assert(data.struct_opt_field().int16_field() == -10)
Expand Down Expand Up @@ -989,8 +950,7 @@ def test_lookup_instance(transient_datareader_qos, test_keyed_type, datareader,
assert(writer_ih == ih)


def test_read(transient_datareader_qos, datareader,
datawriter, cdr_version):
def test_read(transient_datareader_qos, datareader, datawriter):
"""
This test checks:
- DataReader::read
Expand All @@ -1007,7 +967,7 @@ def test_read(transient_datareader_qos, datareader,
assert(0 == len(info_seq))

sample = pytest.dds_type.CompleteTestType()
fill_keyed_complete_test_type(sample, cdr_version)
fill_keyed_complete_test_type(sample)
assert(fastdds.RETCODE_OK == datawriter.write(sample))

assert(datareader.wait_for_unread_message(
Expand All @@ -1022,13 +982,13 @@ def test_read(transient_datareader_qos, datareader,
assert(0 < info_seq[0].source_timestamp.to_ns())
assert(0 < info_seq[0].reception_timestamp.to_ns())
assert(sample == data_seq[0])
check_keyed_complete_test_type(data_seq[0], cdr_version)
check_keyed_complete_test_type(data_seq[0])
assert(fastdds.RETCODE_OK ==
datareader.return_loan(data_seq, info_seq))


def test_read_instance(transient_datareader_qos, test_keyed_type,
datareader, datawriter, cdr_version):
datareader, datawriter):
"""
This test checks:
- DataReader::read_instance
Expand All @@ -1046,7 +1006,7 @@ def test_read_instance(transient_datareader_qos, test_keyed_type,
assert(0 == len(info_seq))

sample = pytest.dds_type.KeyedCompleteTestType()
fill_keyed_complete_test_type(sample, cdr_version)
fill_keyed_complete_test_type(sample)
ih = datawriter.register_instance(sample)
assert(fastdds.RETCODE_OK == datawriter.write(sample, ih))

Expand All @@ -1063,13 +1023,13 @@ def test_read_instance(transient_datareader_qos, test_keyed_type,
assert(0 < info_seq[0].source_timestamp.to_ns())
assert(0 < info_seq[0].reception_timestamp.to_ns())
assert(sample == data_seq[0])
check_keyed_complete_test_type(data_seq[0], cdr_version)
check_keyed_complete_test_type(data_seq[0])
assert(fastdds.RETCODE_OK ==
datareader.return_loan(data_seq, info_seq))


def test_read_next_instance(transient_datareader_qos, test_keyed_type,
datareader, datawriter, cdr_version):
datareader, datawriter):
"""
This test checks:
- DataReader::read_next_instance
Expand All @@ -1087,7 +1047,7 @@ def test_read_next_instance(transient_datareader_qos, test_keyed_type,
assert(0 == len(info_seq))

sample = pytest.dds_type.KeyedCompleteTestType()
fill_keyed_complete_test_type(sample, cdr_version)
fill_keyed_complete_test_type(sample)
assert(fastdds.RETCODE_OK == datawriter.write(sample))

assert(datareader.wait_for_unread_message(
Expand All @@ -1103,13 +1063,13 @@ def test_read_next_instance(transient_datareader_qos, test_keyed_type,
assert(0 < info_seq[0].source_timestamp.to_ns())
assert(0 < info_seq[0].reception_timestamp.to_ns())
assert(sample == data_seq[0])
check_keyed_complete_test_type(data_seq[0], cdr_version)
check_keyed_complete_test_type(data_seq[0])
assert(fastdds.RETCODE_OK ==
datareader.return_loan(data_seq, info_seq))


def test_read_next_sample(transient_datareader_qos, datareader,
datawriter, cdr_version):
datawriter):
"""
This test checks:
- DataReader::read_next_sample
Expand All @@ -1121,7 +1081,7 @@ def test_read_next_sample(transient_datareader_qos, datareader,
data, info))

sample = pytest.dds_type.CompleteTestType()
fill_keyed_complete_test_type(sample, cdr_version)
fill_keyed_complete_test_type(sample)
assert(fastdds.RETCODE_OK == datawriter.write(sample))

assert(datareader.wait_for_unread_message(
Expand All @@ -1132,11 +1092,11 @@ def test_read_next_sample(transient_datareader_qos, datareader,
assert(0 < info.source_timestamp.to_ns())
assert(0 < info.reception_timestamp.to_ns())
assert(sample == data)
check_keyed_complete_test_type(data, cdr_version)
check_keyed_complete_test_type(data)


def test_take(transient_datareader_qos, datareader,
datawriter, cdr_version):
datawriter):
"""
This test checks:
- DataReader::take
Expand All @@ -1153,7 +1113,7 @@ def test_take(transient_datareader_qos, datareader,
assert(0 == len(info_seq))

sample = pytest.dds_type.CompleteTestType()
fill_keyed_complete_test_type(sample, cdr_version)
fill_keyed_complete_test_type(sample)
assert(fastdds.RETCODE_OK == datawriter.write(sample))

assert(datareader.wait_for_unread_message(
Expand All @@ -1168,13 +1128,13 @@ def test_take(transient_datareader_qos, datareader,
assert(0 < info_seq[0].source_timestamp.to_ns())
assert(0 < info_seq[0].reception_timestamp.to_ns())
assert(sample == data_seq[0])
check_keyed_complete_test_type(data_seq[0], cdr_version)
check_keyed_complete_test_type(data_seq[0])
assert(fastdds.RETCODE_OK ==
datareader.return_loan(data_seq, info_seq))


def test_take_instance(transient_datareader_qos, test_keyed_type,
datareader, datawriter, cdr_version):
datareader, datawriter):
"""
This test checks:
- DataReader::take_instance
Expand All @@ -1192,7 +1152,7 @@ def test_take_instance(transient_datareader_qos, test_keyed_type,
assert(0 == len(info_seq))

sample = pytest.dds_type.KeyedCompleteTestType()
fill_keyed_complete_test_type(sample, cdr_version)
fill_keyed_complete_test_type(sample)
ih = datawriter.register_instance(sample)
assert(fastdds.RETCODE_OK == datawriter.write(sample, ih))

Expand All @@ -1209,13 +1169,13 @@ def test_take_instance(transient_datareader_qos, test_keyed_type,
assert(0 < info_seq[0].source_timestamp.to_ns())
assert(0 < info_seq[0].reception_timestamp.to_ns())
assert(sample == data_seq[0])
check_keyed_complete_test_type(data_seq[0], cdr_version)
check_keyed_complete_test_type(data_seq[0])
assert(fastdds.RETCODE_OK ==
datareader.return_loan(data_seq, info_seq))


def test_take_next_instance(transient_datareader_qos, test_keyed_type,
datareader, datawriter, cdr_version):
datareader, datawriter):
"""
This test checks:
- DataReader::take_next_instance
Expand All @@ -1233,7 +1193,7 @@ def test_take_next_instance(transient_datareader_qos, test_keyed_type,
assert(0 == len(info_seq))

sample = pytest.dds_type.KeyedCompleteTestType()
fill_keyed_complete_test_type(sample, cdr_version)
fill_keyed_complete_test_type(sample)
assert(fastdds.RETCODE_OK == datawriter.write(sample))

assert(datareader.wait_for_unread_message(
Expand All @@ -1249,13 +1209,13 @@ def test_take_next_instance(transient_datareader_qos, test_keyed_type,
assert(0 < info_seq[0].source_timestamp.to_ns())
assert(0 < info_seq[0].reception_timestamp.to_ns())
assert(sample == data_seq[0])
check_keyed_complete_test_type(data_seq[0], cdr_version)
check_keyed_complete_test_type(data_seq[0])
assert(fastdds.RETCODE_OK ==
datareader.return_loan(data_seq, info_seq))


def test_take_next_sample(transient_datareader_qos, datareader,
datawriter, cdr_version):
datawriter):
"""
This test checks:
- DataReader::take_next_sample
Expand All @@ -1267,7 +1227,7 @@ def test_take_next_sample(transient_datareader_qos, datareader,
data, info))

sample = pytest.dds_type.CompleteTestType()
fill_keyed_complete_test_type(sample, cdr_version)
fill_keyed_complete_test_type(sample)
assert(fastdds.RETCODE_OK == datawriter.write(sample))

assert(datareader.wait_for_unread_message(
Expand All @@ -1278,7 +1238,7 @@ def test_take_next_sample(transient_datareader_qos, datareader,
assert(0 < info.source_timestamp.to_ns())
assert(0 < info.reception_timestamp.to_ns())
assert(sample == data)
check_keyed_complete_test_type(data, cdr_version)
check_keyed_complete_test_type(data)


def test_get_type(test_type, datareader):
Expand Down

0 comments on commit 6bcf74c

Please sign in to comment.