Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Testing the command "cyclonedds typeof" with a derived topic #242

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 43 additions & 4 deletions tests/test_topic_inheritance.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@
from cyclonedds.sub import DataReader
from cyclonedds.util import duration


BASE_IDL = 'module Hierarchy { @mutable struct Base { string fieldA; }; };'
@dataclass
@annotate.mutable
@annotate.autoid("sequential")
class Base(idl.IdlStruct, typename="Hierarchy.Base"):
fieldA: str


DERIVED_IDL = 'module Hierarchy { struct Derived : Base { string fieldB; }; };'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
DERIVED_IDL = 'module Hierarchy { struct Derived : Base { string fieldB; }; };'
DERIVED_IDL = 'module Hierarchy { @mutable struct Base { string fieldA; }; @mutable struct Derived : Base { string fieldB; }; };'

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @eboasson! Thanks for fixing the "typeof" command and circling back to this pull request. Your code change suggestion is correct, but I found another minor problem in the _type_checker function. I intend to handle the code changes when I return to the office in three weeks.

Stopping supporting Python 3.7 makes sense, as it has already reached its end-of-life. I have yet to check the Python version on Ubuntu or the end-of-life dates for its versions, but it would make sense to follow what has been done in CycloneDDS core. I would need to think about that a bit further to give you a better answer.

@dataclass
@annotate.mutable
@annotate.autoid("sequential")
Expand Down Expand Up @@ -73,11 +74,8 @@ async def test_base_and_derived_topics():
fieldB='Dolor')

tasks = [
# This should not be necessary. I suspect there is a bug in CycloneDDS
_subscriber(Base),
_publisher(Base, base),

# This is the part of the test that really matters
_subscriber(Derived),
_publisher(Derived, derived),
]
Expand All @@ -87,6 +85,21 @@ async def test_base_and_derived_topics():
assert results[2] == results[3]


@pytest.mark.asyncio
async def test_cyclonedds_typeof_command():
'''
Executes the command "cyclonedds typeof" and compares the results with the
expected IDL.
'''
tasks = [
_subscriber(Base),
_subscriber(Derived),
_type_checker(Base, BASE_IDL),
_type_checker(Derived, DERIVED_IDL),
]
await asyncio.gather(*tasks)


async def _publisher(topicClass, value, timeout=2):
'''
Publishes an update with a given value.
Expand All @@ -109,3 +122,29 @@ async def _subscriber(topicClass, timeout=2):
reader = DataReader(participant, topic)
async for update in reader.read_aiter(timeout=duration(seconds=timeout)):
return update


async def _type_checker(topicClass, expectedIdl):
'''
Executes the command "cyclonedds typeof" and compares the result with the
expected IDL.
'''
def _normalise(text):
text = text.replace('\n', '')
text = ' '.join(text.split())
return text

import subprocess
result = subprocess.run(
['cyclonedds', 'typeof', topicClass.__name__, '--suppress-progress-bar'],
stdout = subprocess.PIPE,
check = True)
outputLines = result.stdout.decode().splitlines()

# Skips the first lines of the output (As defined in participant...)
firstIdlLine = 0
while firstIdlLine < len(outputLines) and not outputLines[firstIdlLine].startswith('module'):
firstIdlLine += 1
actualIdl = '\n'.join(outputLines[firstIdlLine:])

assert _normalise(actualIdl) == _normalise(expectedIdl)
Loading