Skip to content

Commit

Permalink
add test for docer copy and move all tests for scenario_execution_docker
Browse files Browse the repository at this point in the history
to separate test package
  • Loading branch information
fmirus committed Oct 10, 2024
1 parent fa3ee0a commit 5963396
Show file tree
Hide file tree
Showing 8 changed files with 140 additions and 0 deletions.
3 changes: 3 additions & 0 deletions test/scenario_execution_docker_test/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Tests of Scenario Execution Library for Docker

The `scenario_execution_docker_test` package tests functionality of `scenario_execution_docker`.
23 changes: 23 additions & 0 deletions test/scenario_execution_docker_test/package.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0"?>
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="3">
<name>scenario_execution_docker_test</name>
<version>1.2.0</version>
<description>Tests for Scenario Execution library for Docker</description>
<author email="[email protected]">Intel Labs</author>
<maintainer email="[email protected]">Intel Labs</maintainer>
<license>Apache-2.0</license>

<exec_depend>scenario_execution_docker</exec_depend>
<exec_depend>scenario_execution_os</exec_depend>
<exec_depend>geometry_msgs</exec_depend>

<test_depend>ament_copyright</test_depend>
<test_depend>ament_flake8</test_depend>
<test_depend>ament_pep257</test_depend>
<test_depend>python3-pytest</test_depend>

<export>
<build_type>ament_python</build_type>
</export>
</package>
Empty file.
4 changes: 4 additions & 0 deletions test/scenario_execution_docker_test/setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[develop]
script_dir=$base/lib/scenario_execution_docker_test
[install]
install_scripts=$base/lib/scenario_execution_docker_test
42 changes: 42 additions & 0 deletions test/scenario_execution_docker_test/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Copyright (C) 2024 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions
# and limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0

""" Setup python package """
from glob import glob
import os
from setuptools import find_namespace_packages, setup

PACKAGE_NAME = 'scenario_execution_docker_test'

setup(
name=PACKAGE_NAME,
version='1.2.0',
packages=find_namespace_packages(),
data_files=[
('share/ament_index/resource_index/packages',
['resource/' + PACKAGE_NAME]),
('share/' + PACKAGE_NAME, ['package.xml']),
(os.path.join('share', PACKAGE_NAME, 'launch'), glob('launch/*launch.py')),
],
install_requires=['setuptools'],
zip_safe=True,
maintainer='Intel Labs',
maintainer_email='[email protected]',
description='Tests for Scenario Execution library for Docker',
license='Apache License 2.0',
tests_require=['pytest'],
entry_points={}
)
68 changes: 68 additions & 0 deletions test/scenario_execution_docker_test/test/test_docker_copy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# Copyright (C) 2024 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions
# and limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0

import py_trees
import unittest
import tempfile
from scenario_execution import ScenarioExecution
from scenario_execution.model.osc2_parser import OpenScenario2Parser
from scenario_execution.model.model_to_py_tree import create_py_tree
from scenario_execution.utils.logging import Logger

from antlr4.InputStream import InputStream


class TestDockerCopy(unittest.TestCase):
# pylint: disable=missing-function-docstring,missing-class-docstring

def setUp(self) -> None:
self.parser = OpenScenario2Parser(Logger('test', False))
self.tmp_dir = tempfile.TemporaryDirectory()
self.scenario_execution = ScenarioExecution(debug=False, log_model=False, live_tree=False,
scenario_file="test.osc", output_dir=self.tmp_dir.name)
self.tree = py_trees.composites.Sequence(name="", memory=True)

def tearDown(self):
self.tmp_dir.cleanup()


def parse(self, scenario_content):
parsed_tree = self.parser.parse_input_stream(InputStream(scenario_content))
model = self.parser.create_internal_model(parsed_tree, self.tree, "test.osc", False)
self.tree = create_py_tree(model, self.tree, self.parser.logger, False)
self.scenario_execution.tree = self.tree
self.scenario_execution.run()

def test_success(self):
self.parse("""
import osc.docker
import osc.helpers
import osc.os
scenario test_success:
timeout(25s)
do parallel:
docker_run(image: 'ubuntu', command: 'sleep 20', detach: true, container_name: 'sleeping_beauty', remove: true)
serial:
docker_exec(container: 'sleeping_beauty', command: 'mkdir -p /tmp/test_dir/')
docker_exec(container: 'sleeping_beauty', command: 'touch /tmp/test_dir/test.txt')
docker_exec(container: 'sleeping_beauty', command: 'touch /tmp/test_dir/test_1.txt')
docker_copy(container: 'sleeping_beauty', file_path: '/tmp/test_dir/')
check_file_exists(file_name: '""" + self.tmp_dir.name + '/test_dir/test.txt' + """')
check_file_exists(file_name: '""" + self.tmp_dir.name + '/test_dir/test_1.txt' + """')
emit end
""")
self.assertTrue(self.scenario_execution.process_results())

0 comments on commit 5963396

Please sign in to comment.