-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Give proper error if "definition" is not given and not any other attributes either. (In that case v is NoneType som you cannot check for "definition") Signed-off-by: Erik Jaegervall <[email protected]>
- Loading branch information
Showing
9 changed files
with
157 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Default file for testing | ||
|
||
length: | ||
definition: Linear extent in space between any two points (ISO 80000-3:2019) | ||
remark: Length does not need to be measured along a straight line. | ||
Length is one of the seven base quantities in the International System of Units (ISO 80000-1). | ||
temperature: | ||
definition: Partial derivative of internal energy with respect to entropy at constant volume | ||
and constant number of particles in the system (ISO 80000-3:2019) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
# Unit file for test purposes only | ||
# Includes a subset of units existing in VSS catalog | ||
# For new test cases consider using | ||
units: | ||
km: | ||
label: kilometer | ||
description: Distance measured in kilometers | ||
domain: distance | ||
celsius: | ||
label: degree celsius | ||
description: Temperature measured in degree celsius | ||
domain: temperature | ||
km: | ||
definition: Length measured in kilometers | ||
unit: kilometer | ||
quantity: length | ||
allowed-datatypes: ['numeric'] | ||
celsius: | ||
definition: Temperature measured in degree celsius | ||
unit: degree celsius | ||
quantity: temperature | ||
allowed-datatypes: ['numeric'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Quantity but no definition which is mandatory | ||
volume: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletions
6
tests/vspec/test_units/expected_default.json → ...spec/test_units_no_quantity/expected.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Copyright (c) 2023 Contributors to COVESA | ||
# | ||
# This program and the accompanying materials are made available under the | ||
# terms of the Mozilla Public License 2.0 which is available at | ||
# https://www.mozilla.org/en-US/MPL/2.0/ | ||
# | ||
# SPDX-License-Identifier: MPL-2.0 | ||
|
||
A: | ||
type: branch | ||
description: Branch A. | ||
|
||
A.Km: | ||
datatype: float | ||
type: sensor | ||
unit: km | ||
description: Something in km. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Default file for testing | ||
volume: | ||
definition: Extent of a three‑dimensional geometrical shape (ISO 80000-3:2019) |
84 changes: 84 additions & 0 deletions
84
tests/vspec/test_units_no_quantity/test_units_no_quantity.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
#!/usr/bin/env python3 | ||
|
||
# Copyright (c) 2023 Contributors to COVESA | ||
# | ||
# This program and the accompanying materials are made available under the | ||
# terms of the Mozilla Public License 2.0 which is available at | ||
# https://www.mozilla.org/en-US/MPL/2.0/ | ||
# | ||
# SPDX-License-Identifier: MPL-2.0 | ||
|
||
import pytest | ||
import os | ||
from typing import Optional | ||
|
||
|
||
# #################### Helper methods ############################# | ||
|
||
@pytest.fixture | ||
def change_test_dir(request, monkeypatch): | ||
# To make sure we run from test directory | ||
monkeypatch.chdir(request.fspath.dirname) | ||
|
||
|
||
def run_unit(vspec_file, unit_argument, expected_file, quantity_argument="", | ||
grep_present: bool = True, grep_string: Optional[str] = None): | ||
test_str = "../../../vspec2json.py --json-pretty " + \ | ||
vspec_file + " " + unit_argument + " " + quantity_argument + " out.json > out.txt 2>&1" | ||
result = os.system(test_str) | ||
assert os.WIFEXITED(result) | ||
assert os.WEXITSTATUS(result) == 0 | ||
|
||
test_str = "diff out.json " + expected_file | ||
result = os.system(test_str) | ||
os.system("rm -f out.json") | ||
assert os.WIFEXITED(result) | ||
assert os.WEXITSTATUS(result) == 0 | ||
|
||
# Verify expected quntity | ||
|
||
if grep_string is not None: | ||
test_str = 'grep \"' + grep_string + '\" out.txt > /dev/null' | ||
result = os.system(test_str) | ||
assert os.WIFEXITED(result) | ||
if grep_present: | ||
assert os.WEXITSTATUS(result) == 0 | ||
else: | ||
assert os.WEXITSTATUS(result) == 1 | ||
|
||
os.system("rm -f out.txt") | ||
|
||
|
||
# #################### Tests ############################# | ||
|
||
def test_default_unit_no_quantity_warning(change_test_dir): | ||
""" | ||
If no quantity file is found it shall only inform about that | ||
""" | ||
run_unit("test.vspec", "-u ../test_units.yaml", "expected.json", "", True, | ||
"No quantities defined") | ||
run_unit("test.vspec", "-u ../test_units.yaml", "expected.json", "", False, | ||
"Quantity length used by unit km has not been defined") | ||
run_unit("test.vspec", "-u ../test_units.yaml", "expected.json", "", False, | ||
"Quantity temperature used by unit celsius has not been defined") | ||
|
||
|
||
def test_default_unit_quantities_missing(change_test_dir): | ||
""" | ||
If quantity file found it shall inform about missing quantities (once for each) | ||
""" | ||
run_unit("test.vspec", "-u ../test_units.yaml", "expected.json", "-q test_quantities.yaml", False, | ||
"No quantities defined") | ||
run_unit("test.vspec", "-u ../test_units.yaml", "expected.json", "-q test_quantities.yaml", True, | ||
"Quantity length used by unit km has not been defined") | ||
run_unit("test.vspec", "-u ../test_units.yaml", "expected.json", "-q test_quantities.yaml", True, | ||
"Quantity temperature used by unit celsius has not been defined") | ||
|
||
|
||
def test_default_unit_quantities_ok(change_test_dir): | ||
run_unit("test.vspec", "-u ../test_units.yaml", "expected.json", "-q ../test_quantities.yaml", False, | ||
"No quantities defined") | ||
run_unit("test.vspec", "-u ../test_units.yaml", "expected.json", "-q ../test_quantities.yaml", False, | ||
"Quantity length used by unit km has not been defined") | ||
run_unit("test.vspec", "-u ../test_units.yaml", "expected.json", "-q ../test_quantities.yaml", False, | ||
"Quantity temperature used by unit celsius has not been defined") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters