This commit is contained in:
Will McGugan
2021-07-05 20:37:54 +01:00
parent c8e14859e5
commit e52af23f0f
5 changed files with 100 additions and 0 deletions

View File

@@ -0,0 +1,49 @@
name: Test Rich module
on: [pull_request]
jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
python-version: ["3.7", "3.8", "3.9"]
defaults:
run:
shell: bash
steps:
- uses: actions/checkout@v1
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
architecture: x64
- name: Install and configure Poetry
uses: snok/install-poetry@v1.1.6
with:
version: 1.1.6
virtualenvs-in-project: true
- name: Install dependencies
run: poetry install
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
- name: Format check with black
run: |
source $VENV
make format-check
- name: Typecheck with mypy
run: |
source $VENV
make typecheck
- name: Test with pytest
run: |
source $VENV
pytest tests -v --cov=./src/textual --cov-report=xml:./coverage.xml --cov-report term-missing
- name: Upload code coverage
uses: codecov/codecov-action@v1.0.10
with:
token: ${{ secrets.CODECOV_TOKEN }}
file: ./coverage.xml
name: rich
flags: unittests
env_vars: OS,PYTHON

11
CHANGELOG.md Normal file
View File

@@ -0,0 +1,11 @@
# Change Log
All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).
## [Unreleased] - yyyy-mm-dd
Here we write upgrading notes for brands. It's a team effort to make them as
straightforward as possible.

4
Makefile Normal file
View File

@@ -0,0 +1,4 @@
test:
pytest --cov-report term-missing --cov=textual tests/ -vv
typecheck:
mypy -p rich --strict

0
tests/__init__.py Normal file
View File

36
tests/test_geometry.py Normal file
View File

@@ -0,0 +1,36 @@
import pytest
from textual.geometry import clamp, Point, Dimensions, Region
def test_clamp():
assert clamp(5, 0, 10) == 5
assert clamp(-1, 0, 10) == 0
assert clamp(11, 0, 10) == 10
assert clamp(0, 0, 10) == 0
assert clamp(10, 0, 10) == 10
def test_point_is_origin():
assert Point(0, 0).is_origin
assert not Point(1, 0).is_origin
def test_point_add():
assert Point(1, 1) + Point(2, 2) == Point(3, 3)
assert Point(1, 2) + Point(3, 4) == Point(4, 6)
with pytest.raises(TypeError):
Point(1, 1) + "foo"
def test_point_sub():
assert Point(1, 1) - Point(2, 2) == Point(-1, -1)
assert Point(3, 4) - Point(2, 1) == Point(1, 3)
with pytest.raises(TypeError):
Point(1, 1) - "foo"
def test_point_blend():
assert Point(1, 2).blend(Point(3, 4), 0) == Point(1, 2)
assert Point(1, 2).blend(Point(3, 4), 1) == Point(3, 4)
assert Point(1, 2).blend(Point(3, 4), 0.5) == Point(2, 3)