Skip to content

Commit

Permalink
Camera and game object done
Browse files Browse the repository at this point in the history
Progress on #121
  • Loading branch information
tinmarr committed May 19, 2022
1 parent e1abe4e commit 9b980e8
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 11 deletions.
16 changes: 12 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,19 @@ You should be good to go. Commits take a bit of time to check (around 10-15 seco
From the repository root, run:

```shell
pytest --cov=rubato --cov-report term-missing rubato/tests
make test
```

This will run all the tests and generate a coverage report with the untested lines. To make life easier, the root Makefile
runs the tests and linting automatically. This can be run using the `make` command (No arguments needed).
This will run all the tests. There are also more make targets for specific tests.

```shell
make all # Run all tests and linting
make # same as make all
make test # Run all tests
make lint # Run linting
make test-no-sdl # Run tests that don't need SDL
make test-no-rub # Run tests that don't need Rubato initialized
```

## Suggest Improvements

Expand All @@ -52,7 +60,7 @@ The docs are built and publish automatically

```shell
pip install --editable .[docs] # install requirements for docs
(cd docs && make live) # start doc server
make docs-live # start doc server
```

### Docstring Guide
Expand Down
9 changes: 9 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@ all:
test:
@pytest --cov=rubato --cov-report term-missing rubato/tests

test-no-rub:
@pytest -m "not rub" --cov=rubato --cov-report term-missing rubato/tests

test-no-sdl:
@pytest -m "not sdl" --cov=rubato --cov-report term-missing rubato/tests

lint:
@echo "Linting Code"
@pylint rubato

docs-live:
@(cd docs && make live)
2 changes: 1 addition & 1 deletion docs/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ BUILDER = dirhtml

save:
@make clear
@$(SPHINXBUILD) -b $(BUILDER) "$(SOURCEDIR)" "$(BUILDDIR)"
@$(SPHINXBUILD) -b -W $(BUILDER) "$(SOURCEDIR)" "$(BUILDDIR)"
@touch build/html/_modules/robots.txt

test:
Expand Down
2 changes: 1 addition & 1 deletion docs/source/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ Noise

Time
====
.. automodule:: rubato.utils.time
.. automodule:: rubato.utils.rb_time
:members:

.. _color:
Expand Down
16 changes: 13 additions & 3 deletions rubato/tests/camera_test.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
"""Test the Camera class"""
from unittest.mock import Mock

import pytest
from rubato.classes.camera import Camera
from rubato.utils.radio import Radio
from rubato.utils.vector import Vector


def test_init():
Expand All @@ -24,9 +27,16 @@ def test_zoom_prop():
callback.assert_called_once_with({"camera": c})


def test_transform():
# TODO once we figure out how to test SDL things
assert True
@pytest.mark.sdl
@pytest.mark.rub
def test_transform(rub):
# pylint: disable=unused-argument
c = Camera()
assert c.transform(Vector(0, 0)) == Vector(0, 0)
assert c.transform(Vector(100, 100)) == Vector(100, 100)
c.zoom = 2
assert c.transform(Vector(0, 0)) == Vector(-200, -100)
assert c.transform(Vector(100, 100)) == Vector(0, 100)


def test_scale():
Expand Down
10 changes: 9 additions & 1 deletion rubato/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import sdl2
import sdl2.ext

from rubato.utils.vector import Vector


@pytest.fixture(scope="module")
def sdl():
Expand All @@ -18,7 +20,13 @@ def sdl():

@pytest.fixture(scope="module")
def rub():
rubato.init({"hidden": True})
"""Initialize Rubato"""
# pylint: disable=unused-argument
rubato.init({
"window_size": Vector(200, 100),
"res": Vector(400, 200),
"hidden": True,
})
yield
sdl2.sdlttf.TTF_Quit()
sdl2.SDL_Quit()
4 changes: 3 additions & 1 deletion rubato/tests/go_comp_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ def test_pass_on_funcs(go, comp):
comp.fixed_update.assert_called_once()


@pytest.mark.rub
@pytest.mark.sdl
def test_draw(monkeypatch, go, comp, rub):
# pylint: disable=unused-argument
go.add(comp)
Expand All @@ -137,7 +139,7 @@ def test_draw(monkeypatch, go, comp, rub):
p3 = Vector(100, 110)
p4 = Vector(100, 90)

draw_line.assert_has_calls([call(p1, p2, Color(0, 255), 6), call(p3, p4, Color(0, 255), 6)])
draw_line.assert_has_calls([call(p1, p2, Color(0, 255), 4), call(p3, p4, Color(0, 255), 4)])


def test_comp_funcs():
Expand Down

0 comments on commit 9b980e8

Please sign in to comment.