-
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.
Signed-off-by: Erik Jaegervall <[email protected]>
- Loading branch information
Showing
6 changed files
with
116 additions
and
4 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,51 @@ | ||
#!/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 sys | ||
import logging | ||
from vspec.model.vsstree import VSSNode | ||
import argparse | ||
from vspec.vss2x import Vss2X | ||
from vspec.vspec2vss_config import Vspec2VssConfig | ||
from vspec.vspec2x import Vspec2X | ||
|
||
|
||
class ExampleGenerator(Vss2X): | ||
""" | ||
This is an example on how easy you can write your own generator | ||
""" | ||
|
||
def __init__(self, keyword: str): | ||
self.keyword = str.lower(keyword) | ||
self.count = 0 | ||
|
||
def handle_node(self, node: VSSNode): | ||
if self.keyword in str.lower(node.comment): | ||
self.count += 1 | ||
for child in node.children: | ||
self.handle_node(child) | ||
|
||
def generate(self, config: argparse.Namespace, signal_root: VSSNode, vspec2vss_config: Vspec2VssConfig, | ||
data_type_root: VSSNode): | ||
self.handle_node(signal_root) | ||
|
||
logging.info("Generating Example output...") | ||
logging.info("I found %d comments with %s", self.count, self.keyword) | ||
|
||
|
||
if __name__ == "__main__": | ||
# JSON supports default | ||
vspec2vss_config = Vspec2VssConfig() | ||
# We do not need an output file | ||
vspec2vss_config.output_file_required = False | ||
# The generator shall know nothing about vspec processing or vspec2vss arguments! | ||
# (Even if it may have some expectations on how the model look like) | ||
vss2json = ExampleGenerator("VSS contributor") | ||
vspec2x = Vspec2X(vss2json, vspec2vss_config) | ||
vspec2x.main(sys.argv[1:]) |
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,27 @@ | ||
# | ||
A: | ||
type: branch | ||
description: Branch A. | ||
|
||
############ Testing Single Line Comments ############## | ||
|
||
A.Erik: | ||
datatype: float | ||
type: sensor | ||
unit: km | ||
description: A sensor. | ||
comment: A VSS contributor! | ||
|
||
A.Sebastian: | ||
datatype: float | ||
type: sensor | ||
unit: km | ||
description: A sensor. | ||
comment: A VSS contributor! | ||
|
||
A.ChuckNorris: | ||
datatype: float | ||
type: sensor | ||
unit: km | ||
description: A sensor. | ||
comment: An actor! |
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,30 @@ | ||
# 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 | ||
|
||
|
||
@pytest.fixture | ||
def change_test_dir(request, monkeypatch): | ||
# To make sure we run from test directory | ||
monkeypatch.chdir(request.fspath.dirname) | ||
|
||
|
||
def test_generator(change_test_dir): | ||
|
||
test_str = "./example_generator.py -u ../vspec/test_units.yaml test.vspec > out.txt 2>&1" | ||
result = os.system(test_str) | ||
assert os.WIFEXITED(result) | ||
assert os.WEXITSTATUS(result) == 0 | ||
|
||
test_str = 'grep \"I found 2 comments with vss contributor\" out.txt > /dev/null' | ||
result = os.system(test_str) | ||
assert os.WIFEXITED(result) | ||
assert os.WEXITSTATUS(result) == 0 | ||
os.system("rm -f out.txt") |
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
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