Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
build --java_language_version=17
build --tool_java_language_version=17
build --java_runtime_version=remotejdk_17
build --tool_java_runtime_version=remotejdk_17
build --@score-baselibs//score/json:base_library=nlohmann

test --test_output=errors

common --registry=https://raw.githubusercontent.com/eclipse-score/bazel_registry/main/
common --registry=https://bcr.bazel.build
1 change: 1 addition & 0 deletions .bazelversion
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
7.4.0
4 changes: 4 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
BasedOnStyle: Google
DerivePointerAlignment: false
ColumnLimit: 100
IndentWidth: 4
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -173,3 +173,10 @@ cython_debug/

# PyPI configuration file
.pypirc

.vscode/
bazel-bin
bazel-out
bazel-testing_tools
bazel-testlogs
MODULE.bazel.lock
43 changes: 43 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
repos:
# Common language-agnostic checks.
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0
hooks:
- id: check-added-large-files
- id: check-merge-conflict
- id: check-yaml
- id: end-of-file-fixer
- id: mixed-line-ending
- id: trailing-whitespace

# Python checks.
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.12.7
hooks:
- id: ruff-format
args: ["--diff"]
- id: ruff-check

# Rust checks.
- repo: https://github.com/doublify/pre-commit-rust
rev: v1.0
hooks:
- id: fmt
args:
["--manifest-path", "test_scenarios_rust/Cargo.toml", "--", "--check"]
- id: cargo-check
args: ["--manifest-path", "test_scenarios_rust/Cargo.toml"]
- id: clippy
args:
[
"--manifest-path",
"test_scenarios_rust/Cargo.toml",
"--all-targets",
"--all-features",
]

# C++ checks.
- repo: https://github.com/pocc/pre-commit-hooks
rev: v1.3.5
hooks:
- id: clang-format
54 changes: 49 additions & 5 deletions .ruff.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,55 @@ line-length = 120
indent-width = 4

[lint]
# Enable Pyflakes (`F`) and a subset of the pycodestyle (`E`) codes by default.
# Unlike Flake8, Ruff doesn't enable pycodestyle warnings (`W`) or
# McCabe complexity (`C901`) by default.
select = ["E4", "E7", "E9", "F", "I"]
ignore = ["F401", "F811"]
select = [
# flake8-boolean-trap
"FBT",
# flake8-bugbear
"B",
# flake8-builtins
"A",
# flake8-commas
"COM",
# flake8-comprehensions
"C4",
# flake8-fixme
"FIX",
# flake8-implicit-str-concat
"ISC",
# flake8-no-pep420
"INP",
# flake8-pie
"PIE",
# flake8-print
"T20",
# flake8-pytest-style
"PT",
# flake8-raise
"RSE",
# flake8-return
"RET",
# flake8-self
"SLF",
# flake8-simplify
"SIM",
# flake8-type-checking
"TC",
# flake8-unused-arguments
"ARG",
# flake8-use-pathlib
"PTH",

# isort
"I",

# pycodestyle error
"E",
# Pyflakes
"F",
# pyupgrade
"UP",
]
ignore = ["F401", "PTH123", "ARG002"]

# Allow fix for all enabled rules (when `--fix`) is provided.
fixable = ["ALL"]
Expand Down
Empty file added BUILD
Empty file.
60 changes: 60 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
"""
'testing-utils' module.
"""

module(
name = "testing-utils",
version = "0.2.0",
)

# Python rules.
bazel_dep(name = "rules_python", version = "1.0.0")

PYTHON_VERSION = "3.12"

python = use_extension("@rules_python//python/extensions:python.bzl", "python")
python.toolchain(
is_default = True,
python_version = PYTHON_VERSION,
)
use_repo(python)

# C++ GoogleTest dependencies.
bazel_dep(name = "googletest", version = "1.14.0")

# Rust rules.
bazel_dep(name = "rules_rust", version = "0.56.0")

# C/C++ rules.
bazel_dep(name = "rules_cc", version = "0.1.1")

# Rust module dependencies.
rust = use_extension("@rules_rust//rust:extensions.bzl", "rust")
rust.toolchain(
edition = "2021",
versions = ["1.85.0"],
)

crate = use_extension("@rules_rust//crate_universe:extensions.bzl", "crate")
crate.from_cargo(
name = "test_scenarios_rust_crates",
cargo_lockfile = "//test_scenarios_rust:Cargo.lock",
manifests = [
"//test_scenarios_rust:Cargo.toml",
],
)
use_repo(crate, "test_scenarios_rust_crates")

# C++ base libs.
archive_override(
module_name = "rules_boost",
strip_prefix = "rules_boost-master",
urls = ["https://github.com/nelhage/rules_boost/archive/refs/heads/master.tar.gz"],
)

bazel_dep(name = "score-baselibs", version = "0.0.0")
git_override(
module_name = "score-baselibs",
commit = "f0a394a602986ddf7abac6a238b9d44535a4b597",
remote = "https://github.com/eclipse-score/baselibs.git",
)
86 changes: 59 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ Test framework tools and helpers for performance stack project.

## Overview

This package provides utility classes and functions to assist with test automation, log handling, and result parsing.
It is designed to be used as a helper library for test frameworks or custom test runners.
This repository provided utilities to assist with test automation, log handling, and result parsing.
It is designed to be a set of helper libraries for test frameworks or custom test runners.

## Features

- **Cargo tools**: Utilities for interacting with Cargo.
- **Test scenarios libraries**: Rust and C++ libraries for implementing test scenarios.
- **Build tools**: Utilities for interacting with Bazel and Cargo.
- **Log container**: A container for storing and querying logs.
- **`ResultEntry`** and subclasses: Structured representation of test log entries.
- **Scenario**: Utilities for defining and running test scenarios.
Expand Down Expand Up @@ -40,7 +41,17 @@ pip install -e .[dev] --config-settings editable_mode=strict

## Usage

### Cargo tools
### Test scenarios utilities

Libraries should be included as a dependency in `Cargo.toml` (Rust) or `BUILD` (C++).

Main components:

- `TestContext` - responsible for listing and running scenarios.
- `Scenario` and `ScenarioGroup` - base classes for defining scenarios and groups.
- `run_cli_app` - runs CLI application based on provided arguments and test context.

### Build tools

#### Get Cargo metadata

Expand All @@ -54,17 +65,17 @@ from testing_utils import cargo_metadata
metadata: dict[str, Any] = cargo_metadata()
```

#### Find executable path
#### Find target path

Path is obtained from Cargo metadata.
CWD must be set to Cargo project.
Find path to executable based on provided target name.

```python
from pathlib import Path
from testing_utils import find_bin_path
from testing_utils import BazelTools

bin_name = "executable_name"
bin_path: Path = find_bin_path(bin_name)
target_name = "target_name"
build_tools = BazelTools()
target_path: Path = build_tools.find_target_path(target_name)
...
```

Expand All @@ -73,47 +84,49 @@ bin_path: Path = find_bin_path(bin_name)
This feature is to ensure flexible usage in pytest context.
Additional configuration is required.

Expected flags depend on implementation, refer to `select_target_path` docs.
Add options to `conftest.py`:

```python
from pathlib import Path

def pytest_addoption(parser):
parser.addoption(
"--bin-path",
"--target-path",
type=Path,
help="Path to test scenarios executable. Search is performed by default.",
)
parser.addoption(
"--bin-name",
"--target-name",
type=str,
default="rust_test_scenarios",
help='Test scenario executable name. Overwritten by "--bin-path".',
help='Test scenario executable name. Overwritten by "--target-path".',
)
```

Usage:

```python
from pathlib import Path
from pytest import FeatureRequest
from testing_utils import select_bin_path
import pytest
from testing_utils import BazelTools

def test_example(request: FeatureRequest) -> None:
bin_path: Path = select_bin_path(request.config)
def test_example(request: pytest.FeatureRequest) -> None:
build_tools = BazelTools()
target_path: Path = build_tools.select_target_path(request.config)
...
```

#### Run Cargo build
#### Run build

Run build based on manifest located in CWD.
CWD must be set to Cargo project.
Run build for selected target.

```python
from testing_utils import cargo_build
from testing_utils import BazelTools

bin_name = "rust_executable"
bin_path: Path = cargo_build(bin_name)
target_name = "target_name"
build_tools = BazelTools()
target_path: Path = build_tools.build(target_name)
...
```

Expand Down Expand Up @@ -169,15 +182,19 @@ Test execution results are provided using two fixtures:
- `results` - executable run results
- `logs` - logs from run

`scenario_name` and `test_config` are marked as abstract and must be implemented.
`build_tools`, `scenario_name` and `test_config` are marked as abstract and must be implemented.

Example implementation:

```python
import pytest
from testing_utils import Scenario, ScenarioResult, LogContainer
from testing_utils import Scenario, ScenarioResult, LogContainer, CargoTools, BuildTools

class TestExample(Scenario):
@pytest.fixture(scope="class")
def build_tools(self) -> BuildTools:
return CargoTools()

@pytest.fixture(scope="class")
def scenario_name(self) -> str:
return "example_scenario_name"
Expand All @@ -203,7 +220,7 @@ class TestExample(Scenario):
...
```

Methods can be overrridden to utilize test-specific fixtures:
Methods can be overridden to utilize test-specific fixtures:

```python
import pytest
Expand All @@ -229,5 +246,20 @@ class TestExample(Scenario)
To run the tests, use:

```bash
pytest -vs .
pytest -vs
```

### `pre-commit`

Install `pre-commit` and set it up in this repository:

```bash
pip install pre-commit
pre-commit install
```

Run `pre-commit`:

```bash
pre-commit run -a
```
11 changes: 9 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[project]
name = "testing-utils"
version = "0.1.1"
dependencies = ["pytest"]
version = "0.2.0"
dependencies = ["pytest==8.4.1", "pytest-html==4.1.1", "pytest-repeat==0.9.4"]
requires-python = ">=3.12"
authors = [
{ name = "Igor Ostrowski", email = "igor.ostrowski.ext@qorix.ai" },
Expand All @@ -15,5 +15,12 @@ readme = "README.md"
requires = ["setuptools>=61.0"]
build-backend = "setuptools.build_meta"

[tool.setuptools]
packages = ["testing_utils"]

[tool.pytest.ini_options]
minversion = "6.0"
testpaths = ["tests"]

[project.optional-dependencies]
dev = ["ruff"]
Loading