Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
da202dc
feat: add cibuildwheel configuration for automated wheel building (#92)
polischuks Jan 31, 2025
2971365
fix: switch to pure Python wheel building
polischuks Jan 31, 2025
d3e6a17
feat: configure platform-dependent wheel building
polischuks Jan 31, 2025
9e5f505
feat: configure wheel building with dependencies
polischuks Jan 31, 2025
cb7d426
fix: correct pip wheel command syntax
polischuks Jan 31, 2025
16c4496
fix: improve cross-platform compatibility in wheel building
polischuks Jan 31, 2025
742cf7d
fix: improve build matrix for better control
polischuks Jan 31, 2025
5884f2e
feat: build single wheel with all dependencies included
polischuks Jan 31, 2025
7da0edb
feat: switch to cibuildwheel
polischuks Jan 31, 2025
b175abd
fix: correct Python version format for cibuildwheel
polischuks Jan 31, 2025
b254740
feat: build single wheel with all dependencies included
polischuks Jan 31, 2025
ae3833f
chore: update poetry.lock after moving dependencies
polischuks Jan 31, 2025
9ef52f8
fix: correct pip wheel command for dependencies
polischuks Jan 31, 2025
c1c4020
feat: switch to python -m build for wheel creation
polischuks Jan 31, 2025
4969be5
feat: switch to PDM for wheel building
polischuks Jan 31, 2025
33f683f
fix: correct pdm import command format
polischuks Jan 31, 2025
c16e6a6
fix: correct PDM build commands
polischuks Feb 3, 2025
7d5d229
feat: add PDM distribution setting to pyproject.toml
polischuks Feb 3, 2025
a35fd77
fix: use pdm config to set distribution setting
polischuks Feb 3, 2025
875a9eb
feat: switch to pip wheel for building
polischuks Feb 3, 2025
a695d43
fix: use pip wheel for all wheel building
polischuks Feb 3, 2025
6ce8a52
feat: use pre-built psutil wheels from our release
polischuks Feb 3, 2025
9fd6b4f
fix: use latest tag for psutil wheels URLs
polischuks Feb 3, 2025
583f7b4
fix: use platform-specific psutil wheels in requirements.txt
polischuks Feb 6, 2025
38c8126
fix: update psutil dependency configuration
polischuks Feb 7, 2025
d360620
fix: correct Linux wheel filenames in requirements.txt
polischuks Feb 7, 2025
7ea670d
feat:
polischuks Feb 7, 2025
444ec74
feat:
polischuks Feb 7, 2025
bf2cde2
fix:
polischuks Feb 7, 2025
1ae86d1
fix:
polischuks Feb 7, 2025
a06124c
fix:
polischuks Feb 7, 2025
23e8644
fix:
polischuks Feb 7, 2025
700bbb7
fix: add hashes to psutil wheel URLs in pyproject.toml
polischuks Feb 7, 2025
cd6354f
fix: update psutil dependency to use a source with hashes in pyprojec…
polischuks Feb 7, 2025
f9f14ff
fix: update psutil dependency to use specific wheel URLs with hashes …
polischuks Feb 7, 2025
9a51b30
fix: update psutil dependency markers for Python version compatibilit…
polischuks Feb 7, 2025
53d7858
fix: add step to clear Poetry cache in GitHub Actions workflow
polischuks Feb 7, 2025
ec54203
fix:
polischuks Feb 7, 2025
3afc3bd
fix: update Poetry install command to exclude hashes
polischuks Feb 7, 2025
e5885ff
Revert "fix: update Poetry install command to exclude hashes"
polischuks Feb 7, 2025
aace98f
fix: update psutil dependency markers for Python version compatibilit…
polischuks Feb 7, 2025
181513c
feat:
polischuks Feb 7, 2025
ab1633e
fix: update psutil wheel URLs to point to specific version releases a…
polischuks Feb 7, 2025
9a77f70
fix: update CI workflow to run ruff check and format commands
polischuks Feb 7, 2025
8e46289
fix: add auto-formatting step to CI workflow using ruff
polischuks Feb 7, 2025
391ec11
fix: update CI workflow to use pull request head repository and refer…
polischuks Feb 7, 2025
0e4e2e0
Backend: Auto format
github-actions[bot] Feb 7, 2025
ffceadf
fix: autoformat (#95)
polischuks Feb 12, 2025
3f86864
feat: update Python version to 3.12 and add mypy configuration
polischuks Feb 12, 2025
185166b
fix: resolve test failures and improve test infrastructure
polischuks Feb 12, 2025
855007f
Backend: Auto format
github-actions[bot] Feb 12, 2025
7154462
fix: enhance error handling in stage_test.py and update CI workflow f…
polischuks Feb 12, 2025
1cee7d1
Backend: Auto format
github-actions[bot] Feb 12, 2025
ebb348a
fix: improve error handling in stage_test.py and enhance CoffeeMachin…
polischuks Feb 13, 2025
3c830f5
Backend: Auto format
github-actions[bot] Feb 13, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
6 changes: 6 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
*.yml text eol=lf
*.yaml text eol=lf
*.py text eol=lf
*.toml text eol=lf
*.md text eol=lf
*.txt text eol=lf
47 changes: 47 additions & 0 deletions .github/workflows/actions/prepare/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: 'Prepare environment'
description: 'Prepare environment'

inputs:
python-version:
description: 'Python version to use'
required: true

runs:
using: "composite"
steps:
- name: Setup PATH
run: echo "/home/runner/.local/bin" >> $GITHUB_PATH
shell: bash

- name: Install Poetry
run: pipx install poetry==$(head -n 1 .poetry-version)
shell: bash

- uses: actions/setup-python@v5
with:
python-version: ${{ inputs.python-version }}
cache: 'poetry'

- name: Clear Poetry cache
run: poetry cache clear --all pypi
shell: bash

- name: Install dependencies and package
run: poetry install --no-interaction --no-ansi
shell: bash

# Setup Node.js for JavaScript tests
- uses: actions/setup-node@v4
with:
node-version: '20'

# Install Node.js dependencies
- name: Install Node.js dependencies
run: npm install
shell: bash

# Setup Go for Go language tests
- uses: actions/setup-go@v5
with:
go-version: '1.21'
cache: false
87 changes: 87 additions & 0 deletions .github/workflows/build-wheels.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
name: Build Wheels

on:
push:
tags:
- 'v*'
workflow_dispatch:

jobs:
build_wheels:
name: Build psutil wheels on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
permissions:
contents: write
strategy:
matrix:
include:
# Linux builds
- os: ubuntu-latest
python-version: '3.10'
- os: ubuntu-latest
python-version: '3.11'
- os: ubuntu-latest
python-version: '3.12'

# Windows builds
- os: windows-latest
python-version: '3.10'
- os: windows-latest
python-version: '3.11'
- os: windows-latest
python-version: '3.12'

# macOS builds
- os: macos-latest
python-version: '3.10'
- os: macos-latest
python-version: '3.11'
- os: macos-latest
python-version: '3.12'

steps:
- uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

- name: Install build dependencies
run: |
python -m pip install pip wheel
shell: bash

- name: Build psutil wheel
run: |
# Create dist directory
mkdir -p dist

# Build psutil wheel
pip wheel psutil==5.8.0 --wheel-dir dist/
shell: bash

- name: Upload to GitHub Actions
uses: actions/upload-artifact@v4
with:
name: dist-${{ matrix.os }}-py${{ matrix.python-version }}
path: dist/*

release:
needs: build_wheels
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/')
permissions:
contents: write
steps:
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
pattern: dist-*
path: dist
merge-multiple: true

- name: Create Release
uses: softprops/action-gh-release@v1
with:
files: dist/*
88 changes: 88 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
name: CI

on:
push:
branches:
- master
- release
pull_request:

concurrency:
group: ${{ github.workflow }}-${{ github.ref_name }}
cancel-in-progress: true

jobs:
lint:
name: Lint with ruff
runs-on: arc-runners-small
timeout-minutes: 30
steps:
- uses: actions/checkout@v4
with:
repository: ${{ github.event.pull_request.head.repo.full_name }}
ref: ${{ github.event.pull_request.head.ref }}
- uses: ./.github/workflows/actions/prepare
with:
python-version: "3.11"
- name: Check files using the ruff formatter
run: |
poetry run ruff check --fix --unsafe-fixes --preview --exit-zero .
poetry run ruff format .
shell: bash
- name: Commit changes
uses: EndBug/add-and-commit@v9
with:
fetch: false
default_author: github_actions
message: 'Backend: Auto format'
add: '.'

mypy:
name: Static Type Checking
runs-on: arc-runners-small
timeout-minutes: 30
steps:
- uses: actions/checkout@v4
- uses: ./.github/workflows/actions/prepare
with:
python-version: "3.12"
- name: Mypy
run: poetry run mypy .
shell: bash

test:
name: Run unit test on ${{ matrix.os }} with Python ${{ matrix.python-version }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
# Self-hosted runner
- os: [ self-hosted, small ]
python-version: "3.10"
- os: [ self-hosted, small ]
python-version: "3.11"
- os: [ self-hosted, small ]
python-version: "3.12"

# Windows
- os: windows-latest
python-version: "3.10.11"
- os: windows-latest
python-version: "3.11"
- os: windows-latest
python-version: "3.12"

# macOS (arm64)
- os: macos-14
python-version: "3.11"
- os: macos-14
python-version: "3.12"
steps:
- uses: actions/checkout@v4
- uses: ./.github/workflows/actions/prepare
with:
python-version: ${{ matrix.python-version }}
- name: Run Tests
run: poetry run python tests/testing.py
shell: bash
2 changes: 2 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on: [ push ]

jobs:
Lint:
if: false
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand All @@ -24,6 +25,7 @@ jobs:
- name: Lint
run: flake8
test-ubuntu:
if: false
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
Expand Down
1 change: 1 addition & 0 deletions .poetry-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2.0.1
1 change: 1 addition & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.10.13
25 changes: 24 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,33 @@
# hs-test-python

Python testing library for Hyperskill projects

It is a framework that simplifies testing educational projects for [Hyperskill](https://hyperskill.org).

It is required to use for Hyperskill projects. The main features are:
The main features are:
* black box testing
* multiple types of tests in a simple unified way (without stdin, with stdin, files, Django, Flask, Matplotlib)
* generating learner-friendly feedback (filtering stack-traces, hints)

## Installation

Install the package directly from GitHub:

```bash
pip install https://github.com/hyperskill/hs-test-python/archive/release.tar.gz
```

The package includes pre-built wheels for psutil, so you don't need a C++ compiler to install it.

## Development

To contribute to the project:

1. Clone the repository
2. Install dependencies with poetry:
```bash
poetry install
```

To learn how to use this library you can go here:
https://github.com/hyperskill/hs-test-python/wiki
34 changes: 16 additions & 18 deletions hstest/__init__.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
__all__ = [
'StageTest',
'DjangoTest',
'FlaskTest',
'PlottingTest',
'SQLTest',

'TestCase',
'SimpleTestCase',

'CheckResult',
'correct',
'wrong',
from __future__ import annotations

'WrongAnswer',
'TestPassed',

'dynamic_test',
'TestedProgram',
__all__ = [
"CheckResult",
"DjangoTest",
"FlaskTest",
"PlottingTest",
"SQLTest",
"SimpleTestCase",
"StageTest",
"TestCase",
"TestPassed",
"TestedProgram",
"WrongAnswer",
"correct",
"dynamic_test",
"wrong",
]

from hstest.dynamic.dynamic_test import dynamic_test
Expand Down
2 changes: 2 additions & 0 deletions hstest/check_result.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# deprecated, but old tests use "from hstest.check_result import CheckResult"
# new way to import is "from hstest import CheckResult"
from __future__ import annotations

from hstest.test_case import CheckResult, correct, wrong # noqa: F401
24 changes: 12 additions & 12 deletions hstest/common/file_utils.py
Original file line number Diff line number Diff line change
@@ -1,42 +1,42 @@
from __future__ import annotations

import contextlib
import os
from typing import Dict

from hstest.exception.testing import FileDeletionError


def create_files(files: Dict[str, str]):
def create_files(files: dict[str, str]) -> None:
for file, content in files.items():
with open(file, 'w') as f:
with open(file, "w", encoding="utf-8") as f:
f.write(content)


def delete_files(files: Dict[str, str]):
for file in files.keys():
def delete_files(files: dict[str, str]) -> None:
for file in files:
if os.path.isfile(file):
try:
os.remove(file)
except PermissionError:
raise FileDeletionError()
raise FileDeletionError


def safe_delete(filename):
def safe_delete(filename) -> None:
if os.path.exists(filename):
try:
with contextlib.suppress(BaseException):
os.remove(filename)
except BaseException:
pass


def walk_user_files(folder):
curr_folder = os.path.abspath(folder)
test_folder = os.path.join(curr_folder, 'test')
test_folder = os.path.join(curr_folder, "test")

for folder, dirs, files in os.walk(curr_folder):
if folder.startswith(test_folder):
continue

if folder == curr_folder:
for file in 'test.py', 'tests.py':
for file in "test.py", "tests.py":
if file in files:
files.remove(file)

Expand Down
Loading