mirror of
https://gitlab.com/splashmapper/splash.git
synced 2026-06-16 12:33:50 +02:00
✅ Added the possibility to select which integration test to run
This commit is contained in:
committed by
Emmanuel Durand
parent
f535ba6b83
commit
bfbb83b27f
+30
-2
@@ -85,8 +85,8 @@ gdb --args splash --doNotSpawn --prefix debug ./data/splash.json
|
||||
Then run each process in `gdb` using the `run` command.
|
||||
|
||||
|
||||
Adding tests
|
||||
------------
|
||||
Testing
|
||||
-------
|
||||
|
||||
Two types of test are used in this project:
|
||||
- unit tests, meant to check that single functions work as designed, are written in C++ and use the [doctest](https://github.com/onqtam/doctest) unit test framework.
|
||||
@@ -94,6 +94,34 @@ Two types of test are used in this project:
|
||||
|
||||
Unit tests are evaluated in the CI whenever a new commit is sent to Gitlab. Integration tests on the other hand, can (sadly, for now) not be ran in the CI as they require an OpenGL 4.5 context. They should be run manually, at least before doing a new release.
|
||||
|
||||
### Executing tests
|
||||
|
||||
To run the unit tests locally, considering that Splash has already been installed once by following the dedicated documentation:
|
||||
```bash
|
||||
cd build
|
||||
make check
|
||||
```
|
||||
|
||||
Similarly to run the integration tests:
|
||||
```bash
|
||||
cd build
|
||||
make check_integration
|
||||
```
|
||||
|
||||
It is also possible to select which tests to run based on their filename. For example to run all tests mentionning images:
|
||||
```bash
|
||||
cd tests/integration_tests
|
||||
splash -P integration_tests.py -- --pattern 'test*image*.py'
|
||||
```
|
||||
|
||||
To run a single test:
|
||||
```bash
|
||||
cd tests/integration_tests
|
||||
splash -P integration_tests.py -- --pattern 'test_sample.py'
|
||||
```
|
||||
|
||||
### Adding tests
|
||||
|
||||
To add a unit test, the steps are:
|
||||
- add the source file for the test in `./tests/unit_tests/`, preferably keeping the same file structure as the source files in `./src` unless a very good reason is given
|
||||
- fill in the source file with the test, see the other tests for reference
|
||||
|
||||
@@ -1,30 +1,53 @@
|
||||
# This should should be ran within Splash:
|
||||
# splash -P integration_tests.py
|
||||
|
||||
import argparse
|
||||
import os
|
||||
import splash
|
||||
import sys
|
||||
|
||||
from unittest import TestLoader, TestResult
|
||||
|
||||
|
||||
def splash_init():
|
||||
runTests()
|
||||
TEST_CASES_PATH = f"{os.path.dirname(os.path.abspath(__file__))}/test_cases"
|
||||
|
||||
|
||||
def splash_loop():
|
||||
def splash_init() -> None:
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('--pattern', dest='pattern', type=str, default="test*.py")
|
||||
parser.add_argument('--list', dest='list', action='store_true', default=False)
|
||||
args = parser.parse_args()
|
||||
|
||||
if args.list is True:
|
||||
files = [
|
||||
file for file in os.listdir(TEST_CASES_PATH)
|
||||
if os.path.isfile(os.path.join(TEST_CASES_PATH, file)) and file.startswith("test_")
|
||||
]
|
||||
print("\n=========================")
|
||||
print("List of Python test files")
|
||||
for file in files:
|
||||
print(f"- {file}")
|
||||
print("\n")
|
||||
else:
|
||||
runTests(pattern=args.pattern)
|
||||
|
||||
splash.set_world_attribute("quit", [])
|
||||
|
||||
|
||||
def splash_loop() -> None:
|
||||
pass
|
||||
|
||||
|
||||
def splash_stop():
|
||||
def splash_stop() -> None:
|
||||
print("Press a key to quit")
|
||||
|
||||
|
||||
def runTests():
|
||||
current_path = os.path.dirname(os.path.abspath(__file__))
|
||||
def runTests(pattern: str) -> None:
|
||||
test_loader = TestLoader()
|
||||
tests = test_loader.discover(start_dir=f"{current_path}/test_cases")
|
||||
tests = test_loader.discover(
|
||||
start_dir=TEST_CASES_PATH,
|
||||
pattern=pattern
|
||||
)
|
||||
|
||||
test_results = TestResult()
|
||||
tests(result=test_results)
|
||||
|
||||
splash.set_world_attribute("quit", [])
|
||||
|
||||
@@ -8,11 +8,14 @@ class TestReplaceImage(SplashTestCase):
|
||||
def test_replace_image(self):
|
||||
print("Replace the Image object multiple times")
|
||||
|
||||
image_file = f"{SplashTestCase.test_dir}/../../../data/share/splash/color_map.png"
|
||||
video_file = f"{SplashTestCase.test_dir}/../../assets/tornado_h264.mov"
|
||||
for i in range(5):
|
||||
filename = f"{SplashTestCase.test_dir}/../../../data/share/splash/color_map.png"
|
||||
splash.set_world_attribute("replaceObject", ["image", "image", "image", "object"])
|
||||
splash.set_object_attribute("image", "file", filename)
|
||||
sleep(1.0)
|
||||
sleep(0.5)
|
||||
splash.set_object_attribute("image", "file", image_file)
|
||||
sleep(2.0)
|
||||
splash.set_world_attribute("replaceObject", ["image", "image_ffmpeg", "image", "object"])
|
||||
sleep(1.0)
|
||||
splash.set_world_attribute("replaceObject", ["image", "image", "image", "object"])
|
||||
sleep(0.5)
|
||||
splash.set_object_attribute("image", "file", video_file)
|
||||
sleep(2.0)
|
||||
|
||||
Reference in New Issue
Block a user