Skip to content
This repository has been archived by the owner on Sep 2, 2024. It is now read-only.

Commit

Permalink
Fix server_type handling
Browse files Browse the repository at this point in the history
Previously you would get an error whatever you specified
  • Loading branch information
erikbosch authored and SebastianSchildt committed Oct 20, 2023
1 parent f953d79 commit 6863fe2
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 1 deletion.
2 changes: 1 addition & 1 deletion dbc2val/dbcfeeder.py
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ def _get_command_line_args_parser() -> argparse.ArgumentParser:
parser.add_argument(
"--server-type",
help="The type of KUKSA.val server to write/read VSS signal to/from",
choices=[server_type.name for server_type in ServerType]
choices=[server_type.value for server_type in ServerType]
)
parser.add_argument(
"--lax-dbc-parsing",
Expand Down
12 changes: 12 additions & 0 deletions dbc2val/test/test_arguments/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
########################################################################
# Copyright (c) 2023 Contributors to the Eclipse Foundation
#
# See the NOTICE file(s) distributed with this work for additional
# information regarding copyright ownership.
#
# This program and the accompanying materials are made available under the
# terms of the Apache License 2.0 which is available at
# http://www.apache.org/licenses/LICENSE-2.0
#
# SPDX-License-Identifier: Apache-2.0
########################################################################
46 changes: 46 additions & 0 deletions dbc2val/test/test_arguments/test_arguments.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
########################################################################
# Copyright (c) 2023 Contributors to the Eclipse Foundation
#
# See the NOTICE file(s) distributed with this work for additional
# information regarding copyright ownership.
#
# This program and the accompanying materials are made available under the
# terms of the Apache License 2.0 which is available at
# http://www.apache.org/licenses/LICENSE-2.0
#
# SPDX-License-Identifier: Apache-2.0
########################################################################

import pytest
import os


@pytest.fixture
def change_test_dir(request, monkeypatch):
# To make sure we run from test directory
monkeypatch.chdir(request.fspath.dirname)


@pytest.mark.parametrize("requested_server, ok_expected", [
('kuksa_databroker', True),
('kuksa_val_server', True),
('KUKSA_DATABROKER', False),
('KUKSA_VAL_SERVER', False)])
def test_server_type(requested_server, ok_expected, change_test_dir):
test_str = "../../dbcfeeder.py --server-type " + requested_server + " --help > out.txt 2>&1"
result = os.system(test_str)
assert os.WIFEXITED(result)
if ok_expected:
assert os.WEXITSTATUS(result) == 0
# Check that we get normal help
test_str = r'grep "\-\-server-type {kuksa_val_server,kuksa_databroker}" out.txt > /dev/null'
else:
assert os.WEXITSTATUS(result) != 0
# Check that we get error
test_str = r'grep "(choose from ' + r"'kuksa_val_server', 'kuksa_databroker')" + r'" out.txt > /dev/null'

result = os.system(test_str)
os.system("cat out.txt")
os.system("rm -f out.json out.txt")
assert os.WIFEXITED(result)
assert os.WEXITSTATUS(result) == 0

0 comments on commit 6863fe2

Please sign in to comment.