Skip to content
Merged
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
20 changes: 20 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ jobs:
make:
name: "${{ matrix.os }} with make"
runs-on: "${{ matrix.os }}"
timeout-minutes: 15
strategy:
fail-fast: false
matrix:
Expand All @@ -40,10 +41,20 @@ jobs:
env:
CC: gcc
CXX: g++
- name: Set up Python for tests
uses: actions/setup-python@v6
with:
python-version: '3.14'
cache: 'pip'
- name: Install test dependencies
run: pip install -r requirements.txt
- name: Test
run: make test

cmake:
name: "${{ matrix.os }} with cmake"
runs-on: "${{ matrix.os }}"
timeout-minutes: 15
strategy:
fail-fast: false
matrix:
Expand All @@ -61,6 +72,15 @@ jobs:
run: |
cmake -B build
cmake --build build -j${{ steps.cpu-cores.outputs.count }}
- name: Set up Python for tests
uses: actions/setup-python@v6
with:
python-version: '3.14'
cache: 'pip'
- name: Install test dependencies
run: pip install -r requirements.txt
- name: Test
run: ctest --test-dir build --verbose

# A dummy job that you can mark as a required check instead of each individual test
test-suite:
Expand Down
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -731,3 +731,6 @@ add_custom_command(TARGET doc-for-web POST_BUILD
${PROJECT_SOURCE_DIR}/Documentation/es/documentation-es
${PROJECT_BINARY_DIR}/doc/es/documentation-es
)

include(CTest)
add_test(NAME pytest COMMAND pytest -vv ${CMAKE_SOURCE_DIR}/tests)
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ clean:
clean-sqlite-shell:
make -C Storage/sqlite clean

test:
make -C test
test: railcontrol
pytest -vv

tools:
make -C tools
Expand Down
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pytest
requests
18 changes: 0 additions & 18 deletions test/Makefile

This file was deleted.

52 changes: 0 additions & 52 deletions test/functions.php

This file was deleted.

5 changes: 0 additions & 5 deletions test/startrailcontrol.sh

This file was deleted.

11 changes: 0 additions & 11 deletions test/stoprailcontrol.sh

This file was deleted.

13 changes: 0 additions & 13 deletions test/testconfig.conf

This file was deleted.

70 changes: 0 additions & 70 deletions test/testcontrols.php

This file was deleted.

24 changes: 0 additions & 24 deletions test/testlocos.php

This file was deleted.

62 changes: 62 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import os
import subprocess
from pathlib import Path

import pytest
import requests
import time


class Client:
def __init__(self, url: str):
self.url = url
self.session = requests.Session()

def cmd(self, cmd: str, **kwargs):
params = kwargs.copy()
params['cmd'] = cmd
response = self.session.get(self.url, params=params)
response.raise_for_status()
return response

def ping(self):
print('Pinging', self.url)
try:
response = self.session.get(self.url, timeout=10)
response.raise_for_status()
except requests.exceptions.ConnectionError:
return False

return True


@pytest.fixture
def service(tmpdir: Path, port: int = 8022):
config = "dbfilename = 'railcontrol.sqlite'\n" \
f"webserverport = {port}\n" \
"numkeepbackups = 0\n"

configfile = tmpdir / 'config.conf'
configfile.write_text(config, 'UTF-8')

url = f"http://localhost:{port}"

command = [os.path.join(os.getcwd(), 'railcontrol'), '--config', str(configfile)]
print("Starting railcontrol")
with subprocess.Popen(command, cwd=tmpdir) as proc:
print("Started", proc.pid)
client = Client(url)

for _ in range(10):
print("Polling", proc.pid)
if proc.poll():
pytest.fail(f"Server exited with code {proc.returncode}")
if client.ping():
yield client
break
time.sleep(0.5)
else:
proc.kill()
pytest.fail("Could not connect to service")

proc.kill()
26 changes: 26 additions & 0 deletions tests/loco_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# locolist

def test_cmd_getlocolist_no_locos(service):
response = service.cmd('getlocolist')

assert response.headers['Content-Type'] == 'text/csv; charset=utf-8'
assert not response.text


# locosave

def test_cmd_locosave_no_data(service):
response = service.cmd('locosave')

assert 'eControl does not exist' in response.text

# loco

def test_cmd_loco_without_loco(service):
response = service.cmd('loco')
assert 'Please select a locomotive' in response.text


def test_cmd_loco_with_loco_does_not_exist(service):
response = service.cmd('loco', loco=1)
assert 'Locomotive does not exist' in response.text
Loading