Skip to content

Commit fad8b71

Browse files
author
Maurizio Branca
committed
Bootstrap E2E testing infrastructure
1 parent b0cbae9 commit fad8b71

File tree

5 files changed

+316
-0
lines changed

5 files changed

+316
-0
lines changed

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ artifacts*
1010

1111
# IDEs config
1212
.idea
13+
.vscode
1314

1415
# macOS
1516
.DS_Store
17+
18+
# Python
19+
__pycache__

poetry.lock

+239
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
[tool.poetry]
2+
name = "arduino-create-agent"
3+
version = "0.1.0"
4+
description = "Project used to run end-to-end test for the Arduino Create Agent"
5+
authors = ["Umberto Baldi <[email protected]>", "Maurizio Branca <[email protected]>"]
6+
license = "GPLv2"
7+
8+
[tool.poetry.dependencies]
9+
python = "^3.9"
10+
11+
[tool.poetry.dev-dependencies]
12+
pytest = "^6.2.1"
13+
requests = "^2.25.1"
14+
invoke = "^1.5.0"
15+
16+
[build-system]
17+
requires = ["poetry-core>=1.0.0"]
18+
build-backend = "poetry.core.masonry.api"

test/conftest.py

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import os
2+
import platform
3+
import signal
4+
import time
5+
from pathlib import Path
6+
7+
import pytest
8+
from invoke import Local
9+
from invoke.context import Context
10+
11+
12+
@pytest.fixture(scope="function")
13+
def agent(pytestconfig):
14+
15+
cli_full_line = str(Path(pytestconfig.rootdir) / "arduino-create-agent")
16+
env = {
17+
# "ARDUINO_DATA_DIR": data_dir,
18+
# "ARDUINO_DOWNLOADS_DIR": downloads_dir,
19+
# "ARDUINO_SKETCHBOOK_DIR": data_dir,
20+
}
21+
run_context = Context()
22+
23+
# TODO: wtf is this?
24+
runner = Local(run_context)
25+
26+
cd_command = "cd"
27+
with run_context.prefix(f'{cd_command} ..'):
28+
runner.run(cli_full_line, echo=True, hide=True, warn=True, env=env, asynchronous=True)
29+
print("cli_full_line", cli_full_line)
30+
time.sleep(.5)
31+
32+
# we block here until the test function using this fixture has returned
33+
yield runner
34+
35+
# Kill the runner's process as we finished our test (platform dependent)
36+
os_signal = signal.SIGTERM
37+
if platform.system() != "Windows":
38+
os_signal = signal.SIGKILL
39+
os.kill(runner.process.pid, os_signal)
40+
41+
42+
@pytest.fixture(scope="session")
43+
def base_url():
44+
return "http://127.0.0.1:8991"

test/test_info.py

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import re
2+
import requests
3+
4+
5+
def test_version(base_url, agent):
6+
7+
resp = requests.get(f"{base_url}/info")
8+
assert resp.status_code == 200
9+
10+
info = resp.json()
11+
assert re.match("[0-9]+.[0-9]+.[0-9]+", info["version"]) is not None

0 commit comments

Comments
 (0)