Skip to content

Commit

Permalink
Refs #20823: Split and modify test
Browse files Browse the repository at this point in the history
Signed-off-by: elianalf <[email protected]>
  • Loading branch information
elianalf committed Jun 11, 2024
1 parent 7326436 commit 7f9bf53
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 101 deletions.
101 changes: 0 additions & 101 deletions test/examples/test_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,104 +159,3 @@ def test_configuration_expected_output(pub_args, sub_args, expected_message, n_m
print(out)

assert(ret)

def test_hello_world():
"""."""
ret = False
out = ''
try:
out = subprocess.check_output(
'@DOCKER_EXECUTABLE@ compose -f hello_world.compose.yml up',
stderr=subprocess.STDOUT,
shell=True,
timeout=30
).decode().split('\n')

sent = 0
received = 0
for line in out:
if 'SENT' in line:
sent += 1
continue

if 'RECEIVED' in line:
received += 1
continue

if sent != 0 and received != 0 and sent * 2 == received:
ret = True
else:
print('ERROR: sent: ' + str(sent) + ', but received: ' + str(received) +
' (expected: ' + str(sent * 2) + ')')
raise subprocess.CalledProcessError(1, '')

except subprocess.CalledProcessError:
for l in out:
print(l)
except subprocess.TimeoutExpired:
print('TIMEOUT')
print(out)

assert(ret)


custom_filter_test_cases = [
(True),
(False)]
@pytest.mark.parametrize("custom_filter", custom_filter_test_cases)
def test_content_filter(custom_filter):
"""."""
ret = False
out = ''
command_prerequisites = 'SUB_ARGS="'
if (custom_filter):
command_prerequisites += '--filter custom" '
else:
command_prerequisites += '--filter default" '

try:
out = subprocess.check_output(command_prerequisites +
'@DOCKER_EXECUTABLE@ compose -f content_filter.compose.yml up',
stderr=subprocess.STDOUT,
shell=True,
timeout=30
).decode().split('\n')

sent = 0
received = 0
data = []
for line in out:
if 'SENT' in line:
sent += 1
continue

if 'RECEIVED' in line:
received += 1
match = re.search(r'index:\s+(\d+)', line)
if match:
number = int(match.group(1))
data.append(number)
continue

ret = True
if sent != 0 and received != 0:
for elem in data:
if (custom_filter):
if not (elem < 4 and elem > 8):
ret = False
else:
if not (elem >= 4 or elem <= 8):
ret = False
else:
print('ERROR: sent: ' + str(sent) + ', received: ' + str(received) +
' but data are out of the filtered range')
raise subprocess.CalledProcessError(1, '')

except subprocess.CalledProcessError:
for l in out:
print(l)
except subprocess.TimeoutExpired:
print('TIMEOUT')
print(out)

assert(ret)
66 changes: 66 additions & 0 deletions test/examples/test_content_filter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
"""."""
import subprocess
import pytest
import re

custom_filter_test_cases = [
('', True),
('', False),
('--reader-filters 0', True),
('--reader-filters 0', False)]
@pytest.mark.parametrize("pub_reader_filters, sub_custom_filter", custom_filter_test_cases)
def test_content_filter(pub_reader_filters, sub_custom_filter):
"""."""
ret = False
out = ''
if (sub_custom_filter):
command_prerequisites = 'PUB_ARGS="' + ' ' + pub_reader_filters + '" SUB_ARGS="' + ' --filter-kind custom" '
else:
command_prerequisites = 'PUB_ARGS="' + ' ' + pub_reader_filters + '" SUB_ARGS="' + ' --filter-kind default" '

try:
out = subprocess.check_output(command_prerequisites +
'@DOCKER_EXECUTABLE@ compose -f content_filter.compose.yml up',
stderr=subprocess.STDOUT,
shell=True,
timeout=30
).decode().split('\n')

sent = 0
received = 0
data = []
for line in out:
if 'SENT' in line:
sent += 1
continue

if 'RECEIVED' in line:
received += 1
match = re.search(r'index:\s+(\d+)', line)
if match:
number = int(match.group(1))
data.append(number)
continue

ret = True
if sent != 0 and received != 0:
for elem in data:
if (sub_custom_filter):
if not (elem < 3 and elem > 8):
ret = False
else:
if not (elem >= 4 or elem <= 8):
ret = False
else:
print('ERROR: sent: ' + str(sent) + ', received: ' + str(received) +
' but data are out of the filtered range')
raise subprocess.CalledProcessError(1, '')

except subprocess.CalledProcessError:
for l in out:
print(l)
except subprocess.TimeoutExpired:
print('TIMEOUT')
print(out)

assert(ret)

0 comments on commit 7f9bf53

Please sign in to comment.