Skip to content

Commit

Permalink
Apply changes
Browse files Browse the repository at this point in the history
Signed-off-by: Irene Bandera <[email protected]>
  • Loading branch information
irenebm committed Jun 22, 2023
1 parent d5fc618 commit ba74b8c
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,5 @@ def __init__(self):
arguments_spy=['--config-path', 'configuration', 'participants'],
commands_spy=[],
output="""- name: Participant_pub\n\
guid: %%guid%%\n"""
guid: %%guid%%\n"""
)
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@

"""Tests for the fastddsspy executable."""

import re

import test_class


Expand Down Expand Up @@ -44,22 +42,7 @@ def __init__(self):
output="""name: HelloWorldTopic\n\
type: HelloWorld\n\
datawriters:\n\
- %%guid%%\n\
- %%guid%%\n\
rate: %%rate%%\n\
dynamic_type_discovered: false\n"""
)

def valid_guid(self, guid) -> bool:
"""
@brief Check if a GUID has the correct pattern.
@param guid: The GUID to check.
@return Returns True if the GUID is valid, False otherwise.
"""
pattern = r'^((-)\s([0-9a-f]{2}\.){11}[0-9a-f]{2}\|([0-9a-f]\.){3}[0-9a-f]{1,})$'
id_guid = guid[guid.find('-'):]
if not re.match(pattern, id_guid):
print('Not valid guid: ')
print(guid)
return False
return True
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@

"""Tests for the fastddsspy executable."""

import re

import test_class


Expand Down Expand Up @@ -48,18 +46,3 @@ def __init__(self):
rate: %%rate%%\n\
dynamic_type_discovered: false\n"""
)

def valid_guid(self, guid) -> bool:
"""
@brief Check if a GUID has the correct pattern.
@param guid: The GUID to check.
@return Returns True if the GUID is valid, False otherwise.
"""
pattern = r'^((-)\s([0-9a-f]{2}\.){11}[0-9a-f]{2}\|([0-9a-f]\.){3}[0-9a-f]{1,})$'
id_guid = guid[guid.find('-'):]
if not re.match(pattern, id_guid):
print('Not valid guid: ')
print(guid)
return False
return True
38 changes: 19 additions & 19 deletions fastddsspy_tool/test/application/test_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def read_command_output(self, proc):
output = ''
count = 0
# max number of loops while can take to avoid waiting forever if something goes wrong
max_count = 500
max_count = 250

while True:
count += 1
Expand Down Expand Up @@ -153,9 +153,8 @@ def valid_guid(self, guid) -> bool:
@param guid: The GUID to check.
@return Returns True if the GUID is valid, False otherwise.
"""
pattern = r'^((guid:)\s([0-9a-f]{2}\.){11}[0-9a-f]{2}\|([0-9a-f]\.){3}[0-9a-f]{1,})$'
id_guid = guid[guid.find('guid:'):]
if not re.match(pattern, id_guid):
pattern = r'^(([0-9a-f]{2}\.){11}[0-9a-f]{2}\|([0-9a-f]\.){3}[0-9a-f]{1,})$'
if not re.match(pattern, guid):
print('Not valid guid: ')
print(guid)
return False
Expand All @@ -168,12 +167,11 @@ def valid_rate(self, rate) -> bool:
@param rate: The rate to check.
@return Returns True if the rate is valid, False otherwise.
"""
pattern_1 = r'^((rate:)\s\d*\.?\d*\s(Hz))$' # rate: 10.5 Hz
pattern_2 = r'^((rate:)\s(inf)\s(Hz))$' # rate: inf Hz
id_rate = rate[rate.find('rate:'):]
if re.match(pattern_1, id_rate):
pattern_1 = r'^(\d*\.?\d*\s(Hz))$' # rate: 10.5 Hz
pattern_2 = r'^((inf)\s(Hz))$' # rate: inf Hz
if re.match(pattern_1, rate):
return True
if re.match(pattern_2, id_rate):
if re.match(pattern_2, rate):
return True
print('Not valid rate: ')
print(rate)
Expand Down Expand Up @@ -212,9 +210,11 @@ def valid_output(self, output) -> bool:
rate = True
for i in range(len(lines_expected_output)):
if '%%guid%%' in lines_expected_output[i]:
guid = self.valid_guid(lines_output[i])
start_guid_position = lines_expected_output[i].find('%%guid%%')
guid = self.valid_guid(lines_output[i][start_guid_position:])
elif '%%rate%%' in lines_expected_output[i]:
rate = self.valid_rate(lines_output[i])
start_rate_position = lines_expected_output[i].find('%%rate%%')
rate = self.valid_rate(lines_output[i][start_rate_position:])
elif lines_expected_output[i] != lines_output[i]:
print('Output: ')
print(output)
Expand All @@ -223,12 +223,12 @@ def valid_output(self, output) -> bool:
return False
return (guid and rate)

def stop_tool(self, proc) -> int:
def stop_tool(self, proc) -> bool:
"""
@brief Stop the running Spy.
@param proc: The subprocess object representing the running Spy.
@return Returns 1 if the Spy is successfully stopped, 0 otherwise.
@return Returns True if the Spy is successfully stopped, False otherwise.
"""
try:
proc.communicate(input='exit\n', timeout=10)[0]
Expand All @@ -239,16 +239,16 @@ def stop_tool(self, proc) -> int:

if not self.is_stop(proc):
print('ERROR: DDS Spy still running')
return 0
return False

return 1
return True

def stop_dds(self, proc) -> int:
def stop_dds(self, proc) -> bool:
"""
@brief Stop the DDS publisher.
@param proc: The subprocess object representing the running DDS publisher.
@return Returns 1 if the DDS publisher is successfully stopped, 0 otherwise.
@return Returns True if the DDS publisher is successfully stopped, False otherwise.
"""
if self.dds:
try:
Expand All @@ -261,9 +261,9 @@ def stop_dds(self, proc) -> int:

if not self.is_stop(proc):
print('ERROR: DDS Publisher still running')
return 0
return False

return 1
return True

def is_stop(self, proc) -> bool:
"""
Expand Down

0 comments on commit ba74b8c

Please sign in to comment.