-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Add tests with pytest #133
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
4f9b9bb
5f313ae
e483a53
30776ef
29efd9c
063202f
3451752
d310caf
abb220d
95ae968
f39ef13
3e90eea
572d881
8955f34
09b18f9
dfcc8c3
c51bd07
df6f2d2
1a23c72
259bba3
b312320
7afa989
4d937d7
62fe97f
88200df
40f997f
25a9434
f58fb85
c746120
014dbb0
1ad7143
b38d00a
349ec04
f1d8da3
9f645d0
7fdba8e
0dfd8cc
55c9899
67241f6
c756d45
22b408b
0752ef0
11144c5
7b5f0a9
217f6b0
de21699
7690ed7
420aae2
2a6c276
85291ba
c4ed7f2
24955eb
b83ab84
13c765d
a963965
4f4aba1
21438ae
ade21ea
4a553e1
7f28eb6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,7 @@ jobs: | |
|
||
- os: linux | ||
language: python | ||
python: 3.7 | ||
python: 3.7 | ||
install: | ||
- pip3 install --upgrade pip | ||
- pip3 install -r ./.travis/travis-requirements.txt | ||
|
@@ -39,6 +39,11 @@ jobs: | |
language: sh | ||
python: 3.6 | ||
env: PYVER="3.6.10" | ||
before_install: | ||
- ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" < /dev/null 2> /dev/null | ||
- brew install ffmpeg | ||
- brew cask install mactex | ||
- eval "$(/usr/libexec/path_helper)" | ||
install: | ||
- pip3 install --upgrade pip | ||
- pip3 install -r ./.travis/travis-requirements.txt | ||
|
@@ -51,6 +56,11 @@ jobs: | |
language: sh | ||
python: 3.7 | ||
env: PYVER="3.7.7" | ||
before_install: | ||
- ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" < /dev/null 2> /dev/null | ||
- brew install ffmpeg | ||
- brew cask install mactex | ||
- eval "$(/usr/libexec/path_helper)" | ||
install: | ||
- pip3 install --upgrade pip | ||
- pip3 install -r ./.travis/travis-requirements.txt | ||
|
@@ -63,6 +73,11 @@ jobs: | |
language: sh | ||
python: 3.8 | ||
env: PYVER="3.8.0" # Using Python 3.8.0 due to error with rich | ||
before_install: | ||
- ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" < /dev/null 2> /dev/null | ||
- brew install ffmpeg | ||
- brew cask install mactex | ||
- eval "$(/usr/libexec/path_helper)" | ||
install: | ||
- pip3 install --upgrade pip | ||
- pip3 install -r ./.travis/travis-requirements.txt | ||
|
@@ -80,15 +95,14 @@ jobs: | |
install: | ||
- choco install python --version=$PYVER | ||
- export PATH="/c/$PYDIR:/c/$PYDIR/Scripts:$PATH" | ||
- choco install ffmpeg | ||
- cmd.exe //c "RefreshEnv.cmd" | ||
- python -m pip install --upgrade pip | ||
- python -m pip install --user -r ./.travis/travis-requirements.txt | ||
- python ./scripts/pycairoinstall.py | ||
- cmd.exe //c "RefreshEnv.cmd" | ||
- python -m pip install --user . | ||
script: | ||
- python -m pytest | ||
- python -m pytest --skip_end_to_end -rs | ||
|
||
- os: windows | ||
language: sh | ||
|
@@ -97,15 +111,14 @@ jobs: | |
install: | ||
- choco install python --version=$PYVER | ||
- export PATH="/c/$PYDIR:/c/$PYDIR/Scripts:$PATH" | ||
- choco install ffmpeg | ||
- cmd.exe //c "RefreshEnv.cmd" | ||
- python -m pip install --upgrade pip | ||
- python -m pip install --user -r ./.travis/travis-requirements.txt | ||
- python ./scripts/pycairoinstall.py | ||
- cmd.exe //c "RefreshEnv.cmd" | ||
- python -m pip install --user . | ||
script: | ||
- python -m pytest | ||
- python -m pytest --skip_end_to_end -rs | ||
|
||
- os: windows | ||
language: sh | ||
|
@@ -114,19 +127,18 @@ jobs: | |
install: | ||
- choco install python --version=$PYVER | ||
- export PATH="/c/$PYDIR:/c/$PYDIR/Scripts:$PATH" | ||
- choco install ffmpeg | ||
- cmd.exe //c "RefreshEnv.cmd" | ||
- python -m pip install --upgrade pip | ||
- python -m pip install --user -r ./.travis/travis-requirements.txt | ||
- python ./scripts/pycairoinstall.py | ||
- cmd.exe //c "RefreshEnv.cmd" | ||
- python -m pip install --user . | ||
script: | ||
- python -m pytest | ||
- python -m pytest --skip_end_to_end -rs | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same thing (as far as DRY goes) for Windows here. We probably want to use a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This comment was supposed to be 3 lines up in |
||
|
||
before_install: | ||
- if [ "$TRAVIS_OS_NAME" == "osx" ]; then chmod +x ./.travis/osx.sh; sh ./.travis/osx.sh; fi | ||
|
||
- if [ "$TRAVIS_OS_NAME" == "linux" ]; then chmod +x ./.travis/linux.sh; sh ./.travis/linux.sh; fi | ||
branches: | ||
only: | ||
- master | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
##### THIS IS FOR TRAVIS BUILDS, DO NOT RUN THIS ON YOUR COMPUTER! ##### | ||
|
||
sudo apt update | ||
sudo apt install -y ffmpeg | ||
sudo apt-get -y install texlive texlive-latex-extra texlive-fonts-extra texlive-latex-recommended texlive-science texlive-fonts-extra tipa |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
from manim import dirs | ||
huguesdevimeux marked this conversation as resolved.
Show resolved
Hide resolved
|
||
from manim import config | ||
|
||
import pytest | ||
import numpy as np | ||
import os | ||
import sys | ||
import logging | ||
|
||
|
||
def pytest_addoption(parser): | ||
parser.addoption("--skip_end_to_end", action="store_true", default=False, | ||
help="Will skip all the end-to-end tests. Useful when ffmpeg is not installed, e.g. on Windows jobs.") | ||
|
||
|
||
def pytest_configure(config): | ||
config.addinivalue_line( | ||
"markers", "skip_end_to_end: mark test as end_to_end test") | ||
|
||
|
||
def pytest_collection_modifyitems(config, items): | ||
if not config.getoption("--skip_end_to_end"): | ||
return | ||
else: | ||
skip_end_to_end = pytest.mark.skip( | ||
reason="End to end test skipped due to --skip_end_to_end flag") | ||
for item in items: | ||
if "skip_end_to_end" in item.keywords: | ||
item.add_marker(skip_end_to_end) | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def python_version(): | ||
return "python3" if sys.platform == "darwin" else "python" | ||
|
||
|
||
@pytest.fixture | ||
def get_config_test(): | ||
"""Function used internally by pytest as a fixture. Return the Configuration for the scenes rendered. The config is the one used when | ||
calling the flags -s -l -dry_run | ||
""" | ||
CONFIG = { | ||
'camera_config': { | ||
'frame_rate': 15, | ||
'pixel_height': 480, | ||
'pixel_width': 854 | ||
}, | ||
'end_at_animation_number': None, | ||
'file_writer_config': { | ||
'file_name': None, | ||
'input_file_path': 'test.py', | ||
'movie_file_extension': '.mp4', | ||
'png_mode': 'RGB', | ||
'save_as_gif': False, | ||
'save_last_frame': False, | ||
'save_pngs': False, | ||
'write_to_movie': False | ||
}, | ||
'leave_progress_bars': False, | ||
'skip_animations': True, | ||
'start_at_animation_number': None | ||
} | ||
return CONFIG |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import subprocess | ||
import os | ||
from shutil import rmtree | ||
import pytest | ||
|
||
|
||
def capture(command): | ||
proc = subprocess.Popen(command, | ||
stdout=subprocess.PIPE, | ||
stderr=subprocess.PIPE, | ||
) | ||
out, err = proc.communicate() | ||
return out, err, proc.returncode | ||
|
||
|
||
def test_help(python_version): | ||
command = [python_version, "-m", "manim", "--help"] | ||
out, err, exitcode = capture(command) | ||
assert exitcode == 0, f"Manim has been installed incorrectly. Please refer to the troubleshooting section on the wiki. Error: {err}" | ||
|
||
|
||
@pytest.mark.skip_end_to_end | ||
def test_basicScene(python_version): | ||
""" Simulate SquareToCircle. The cache will be saved in tests_caches/media_temp (temporary directory). This is mainly intended to test the partial-movies process. """ | ||
path_basic_scene = os.path.join("tests", "tests_data", "basic_scenes.py") | ||
path_output = os.path.join("tests", "tests_cache", "media_temp") | ||
command = [python_version, "-m", "manim", path_basic_scene, | ||
"SquareToCircle", "-l", "--media_dir", path_output] | ||
out, err, exitcode = capture(command) | ||
assert exitcode == 0, err | ||
assert os.path.exists(os.path.join( | ||
path_output, "videos", "basic_scenes", "480p15", "SquareToCircle.mp4")), err | ||
rmtree(path_output) | ||
|
||
@pytest.mark.skip_end_to_end | ||
def test_WriteStuff(python_version): | ||
"""This is mainly intended to test the caching process of the tex objects""" | ||
path_basic_scene = os.path.join("tests", "tests_data", "basic_scenes.py") | ||
path_output = os.path.join("tests", "tests_cache", "media_temp") | ||
command = [python_version, "-m", "manim", path_basic_scene, | ||
"WriteStuff", "-l", "--media_dir", path_output] | ||
out, err, exitcode = capture(command) | ||
assert exitcode == 0, err | ||
assert os.path.exists(os.path.join( | ||
path_output, "videos", "basic_scenes", "480p15", "WriteStuff.mp4")), err | ||
rmtree(path_output) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
from manim import * | ||
from testing_utils import utils_test_scenes, get_scenes_to_test | ||
|
||
|
||
class ShowCreationTest(Scene): | ||
def construct(self): | ||
square = Square() | ||
self.play(ShowCreation(square)) | ||
|
||
|
||
class UncreateTest(Scene): | ||
def construct(self): | ||
square = Square() | ||
self.add(square) | ||
self.play(Uncreate(square)) | ||
|
||
|
||
class DrawBorderThenFillTest(Scene): | ||
def construct(self): | ||
square = Square(fill_opacity=1) | ||
self.play(DrawBorderThenFill(square)) | ||
|
||
|
||
# NOTE : Here should be the Write Test. But for some reasons it appears that this function is untestable (see issue #157) | ||
leotrs marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
class FadeOutTest(Scene): | ||
def construct(self): | ||
square = Square() | ||
self.add(square) | ||
self.play(FadeOut(square)) | ||
|
||
|
||
class FadeInTest(Scene): | ||
def construct(self): | ||
square = Square() | ||
self.play(FadeIn(square)) | ||
|
||
|
||
class FadeInFromTest(Scene): | ||
def construct(self): | ||
square = Square() | ||
self.play(FadeInFrom(square, direction=UP)) | ||
|
||
|
||
class FadeInFromDownTest(Scene): | ||
def construct(self): | ||
square = Square() | ||
self.play(FadeInFromDown(square)) | ||
|
||
|
||
class FadeOutAndShiftTest(Scene): | ||
def construct(self): | ||
square = Square() | ||
self.play(FadeOutAndShift(square, direction=UP)) | ||
|
||
|
||
class FadeInFromLargeTest(Scene): | ||
def construct(self): | ||
square = Square() | ||
self.play(FadeInFromLarge(square)) | ||
|
||
|
||
class GrowFromPointTest(Scene): | ||
def construct(self): | ||
square = Square() | ||
self.play(GrowFromPoint(square, np.array((1, 1, 0)))) | ||
|
||
|
||
class GrowFromCenterTest(Scene): | ||
def construct(self): | ||
square = Square() | ||
self.play(GrowFromCenter(square)) | ||
|
||
|
||
class GrowFromEdgeTest(Scene): | ||
def construct(self): | ||
square = Square() | ||
self.play(GrowFromEdge(square, DOWN)) | ||
|
||
|
||
class SpinInFromNothingTest(Scene): | ||
def construct(self): | ||
square = Square() | ||
self.play(SpinInFromNothing(square)) | ||
|
||
|
||
class ShrinkToCenterTest(Scene): | ||
def construct(self): | ||
square = Square() | ||
self.play(ShrinkToCenter(square)) | ||
|
||
def test_scenes(get_config_test): | ||
utils_test_scenes(get_scenes_to_test(__name__), get_config_test, "creation") |
Uh oh!
There was an error while loading. Please reload this page.