Skip to content

Commit 4b6492b

Browse files
authored
Merge pull request #133 from huguesdevimeux/testings
Add tests with pytest (WIP)
2 parents 06accee + 7f28eb6 commit 4b6492b

File tree

162 files changed

+1549
-70
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

162 files changed

+1549
-70
lines changed

.travis.yml

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414

1515
- os: linux
1616
language: python
17-
python: 3.7
17+
python: 3.7
1818
install:
1919
- pip3 install --upgrade pip
2020
- pip3 install -r ./.travis/travis-requirements.txt
@@ -39,6 +39,11 @@ jobs:
3939
language: sh
4040
python: 3.6
4141
env: PYVER="3.6.10"
42+
before_install:
43+
- ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" < /dev/null 2> /dev/null
44+
- brew install ffmpeg
45+
- brew cask install mactex
46+
- eval "$(/usr/libexec/path_helper)"
4247
install:
4348
- pip3 install --upgrade pip
4449
- pip3 install -r ./.travis/travis-requirements.txt
@@ -51,6 +56,11 @@ jobs:
5156
language: sh
5257
python: 3.7
5358
env: PYVER="3.7.7"
59+
before_install:
60+
- ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" < /dev/null 2> /dev/null
61+
- brew install ffmpeg
62+
- brew cask install mactex
63+
- eval "$(/usr/libexec/path_helper)"
5464
install:
5565
- pip3 install --upgrade pip
5666
- pip3 install -r ./.travis/travis-requirements.txt
@@ -63,6 +73,11 @@ jobs:
6373
language: sh
6474
python: 3.8
6575
env: PYVER="3.8.0" # Using Python 3.8.0 due to error with rich
76+
before_install:
77+
- ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" < /dev/null 2> /dev/null
78+
- brew install ffmpeg
79+
- brew cask install mactex
80+
- eval "$(/usr/libexec/path_helper)"
6681
install:
6782
- pip3 install --upgrade pip
6883
- pip3 install -r ./.travis/travis-requirements.txt
@@ -80,15 +95,14 @@ jobs:
8095
install:
8196
- choco install python --version=$PYVER
8297
- export PATH="/c/$PYDIR:/c/$PYDIR/Scripts:$PATH"
83-
- choco install ffmpeg
8498
- cmd.exe //c "RefreshEnv.cmd"
8599
- python -m pip install --upgrade pip
86100
- python -m pip install --user -r ./.travis/travis-requirements.txt
87101
- python ./scripts/pycairoinstall.py
88102
- cmd.exe //c "RefreshEnv.cmd"
89103
- python -m pip install --user .
90104
script:
91-
- python -m pytest
105+
- python -m pytest --skip_end_to_end -rs
92106

93107
- os: windows
94108
language: sh
@@ -97,15 +111,14 @@ jobs:
97111
install:
98112
- choco install python --version=$PYVER
99113
- export PATH="/c/$PYDIR:/c/$PYDIR/Scripts:$PATH"
100-
- choco install ffmpeg
101114
- cmd.exe //c "RefreshEnv.cmd"
102115
- python -m pip install --upgrade pip
103116
- python -m pip install --user -r ./.travis/travis-requirements.txt
104117
- python ./scripts/pycairoinstall.py
105118
- cmd.exe //c "RefreshEnv.cmd"
106119
- python -m pip install --user .
107120
script:
108-
- python -m pytest
121+
- python -m pytest --skip_end_to_end -rs
109122

110123
- os: windows
111124
language: sh
@@ -114,19 +127,18 @@ jobs:
114127
install:
115128
- choco install python --version=$PYVER
116129
- export PATH="/c/$PYDIR:/c/$PYDIR/Scripts:$PATH"
117-
- choco install ffmpeg
118130
- cmd.exe //c "RefreshEnv.cmd"
119131
- python -m pip install --upgrade pip
120132
- python -m pip install --user -r ./.travis/travis-requirements.txt
121133
- python ./scripts/pycairoinstall.py
122134
- cmd.exe //c "RefreshEnv.cmd"
123135
- python -m pip install --user .
124136
script:
125-
- python -m pytest
137+
- python -m pytest --skip_end_to_end -rs
126138

127139
before_install:
128140
- if [ "$TRAVIS_OS_NAME" == "osx" ]; then chmod +x ./.travis/osx.sh; sh ./.travis/osx.sh; fi
129-
141+
- if [ "$TRAVIS_OS_NAME" == "linux" ]; then chmod +x ./.travis/linux.sh; sh ./.travis/linux.sh; fi
130142
branches:
131143
only:
132144
- master

.travis/linux.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
##### THIS IS FOR TRAVIS BUILDS, DO NOT RUN THIS ON YOUR COMPUTER! #####
2+
3+
sudo apt update
4+
sudo apt install -y ffmpeg
5+
sudo apt-get -y install texlive texlive-latex-extra texlive-fonts-extra texlive-latex-recommended texlive-science texlive-fonts-extra tipa

tests/conftest.py

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
from manim import dirs
2+
from manim import config
3+
4+
import pytest
5+
import numpy as np
6+
import os
7+
import sys
8+
import logging
9+
10+
11+
def pytest_addoption(parser):
12+
parser.addoption("--skip_end_to_end", action="store_true", default=False,
13+
help="Will skip all the end-to-end tests. Useful when ffmpeg is not installed, e.g. on Windows jobs.")
14+
15+
16+
def pytest_configure(config):
17+
config.addinivalue_line(
18+
"markers", "skip_end_to_end: mark test as end_to_end test")
19+
20+
21+
def pytest_collection_modifyitems(config, items):
22+
if not config.getoption("--skip_end_to_end"):
23+
return
24+
else:
25+
skip_end_to_end = pytest.mark.skip(
26+
reason="End to end test skipped due to --skip_end_to_end flag")
27+
for item in items:
28+
if "skip_end_to_end" in item.keywords:
29+
item.add_marker(skip_end_to_end)
30+
31+
32+
@pytest.fixture(scope="module")
33+
def python_version():
34+
return "python3" if sys.platform == "darwin" else "python"
35+
36+
37+
@pytest.fixture
38+
def get_config_test():
39+
"""Function used internally by pytest as a fixture. Return the Configuration for the scenes rendered. The config is the one used when
40+
calling the flags -s -l -dry_run
41+
"""
42+
CONFIG = {
43+
'camera_config': {
44+
'frame_rate': 15,
45+
'pixel_height': 480,
46+
'pixel_width': 854
47+
},
48+
'end_at_animation_number': None,
49+
'file_writer_config': {
50+
'file_name': None,
51+
'input_file_path': 'test.py',
52+
'movie_file_extension': '.mp4',
53+
'png_mode': 'RGB',
54+
'save_as_gif': False,
55+
'save_last_frame': False,
56+
'save_pngs': False,
57+
'write_to_movie': False
58+
},
59+
'leave_progress_bars': False,
60+
'skip_animations': True,
61+
'start_at_animation_number': None
62+
}
63+
return CONFIG

tests/test_CLI.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import subprocess
2+
import os
3+
from shutil import rmtree
4+
import pytest
5+
6+
7+
def capture(command):
8+
proc = subprocess.Popen(command,
9+
stdout=subprocess.PIPE,
10+
stderr=subprocess.PIPE,
11+
)
12+
out, err = proc.communicate()
13+
return out, err, proc.returncode
14+
15+
16+
def test_help(python_version):
17+
command = [python_version, "-m", "manim", "--help"]
18+
out, err, exitcode = capture(command)
19+
assert exitcode == 0, f"Manim has been installed incorrectly. Please refer to the troubleshooting section on the wiki. Error: {err}"
20+
21+
22+
@pytest.mark.skip_end_to_end
23+
def test_basicScene(python_version):
24+
""" Simulate SquareToCircle. The cache will be saved in tests_caches/media_temp (temporary directory). This is mainly intended to test the partial-movies process. """
25+
path_basic_scene = os.path.join("tests", "tests_data", "basic_scenes.py")
26+
path_output = os.path.join("tests", "tests_cache", "media_temp")
27+
command = [python_version, "-m", "manim", path_basic_scene,
28+
"SquareToCircle", "-l", "--media_dir", path_output]
29+
out, err, exitcode = capture(command)
30+
assert exitcode == 0, err
31+
assert os.path.exists(os.path.join(
32+
path_output, "videos", "basic_scenes", "480p15", "SquareToCircle.mp4")), err
33+
rmtree(path_output)
34+
35+
@pytest.mark.skip_end_to_end
36+
def test_WriteStuff(python_version):
37+
"""This is mainly intended to test the caching process of the tex objects"""
38+
path_basic_scene = os.path.join("tests", "tests_data", "basic_scenes.py")
39+
path_output = os.path.join("tests", "tests_cache", "media_temp")
40+
command = [python_version, "-m", "manim", path_basic_scene,
41+
"WriteStuff", "-l", "--media_dir", path_output]
42+
out, err, exitcode = capture(command)
43+
assert exitcode == 0, err
44+
assert os.path.exists(os.path.join(
45+
path_output, "videos", "basic_scenes", "480p15", "WriteStuff.mp4")), err
46+
rmtree(path_output)

tests/test_creation.py

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
from manim import *
2+
from testing_utils import utils_test_scenes, get_scenes_to_test
3+
4+
5+
class ShowCreationTest(Scene):
6+
def construct(self):
7+
square = Square()
8+
self.play(ShowCreation(square))
9+
10+
11+
class UncreateTest(Scene):
12+
def construct(self):
13+
square = Square()
14+
self.add(square)
15+
self.play(Uncreate(square))
16+
17+
18+
class DrawBorderThenFillTest(Scene):
19+
def construct(self):
20+
square = Square(fill_opacity=1)
21+
self.play(DrawBorderThenFill(square))
22+
23+
24+
# NOTE : Here should be the Write Test. But for some reasons it appears that this function is untestable (see issue #157)
25+
26+
class FadeOutTest(Scene):
27+
def construct(self):
28+
square = Square()
29+
self.add(square)
30+
self.play(FadeOut(square))
31+
32+
33+
class FadeInTest(Scene):
34+
def construct(self):
35+
square = Square()
36+
self.play(FadeIn(square))
37+
38+
39+
class FadeInFromTest(Scene):
40+
def construct(self):
41+
square = Square()
42+
self.play(FadeInFrom(square, direction=UP))
43+
44+
45+
class FadeInFromDownTest(Scene):
46+
def construct(self):
47+
square = Square()
48+
self.play(FadeInFromDown(square))
49+
50+
51+
class FadeOutAndShiftTest(Scene):
52+
def construct(self):
53+
square = Square()
54+
self.play(FadeOutAndShift(square, direction=UP))
55+
56+
57+
class FadeInFromLargeTest(Scene):
58+
def construct(self):
59+
square = Square()
60+
self.play(FadeInFromLarge(square))
61+
62+
63+
class GrowFromPointTest(Scene):
64+
def construct(self):
65+
square = Square()
66+
self.play(GrowFromPoint(square, np.array((1, 1, 0))))
67+
68+
69+
class GrowFromCenterTest(Scene):
70+
def construct(self):
71+
square = Square()
72+
self.play(GrowFromCenter(square))
73+
74+
75+
class GrowFromEdgeTest(Scene):
76+
def construct(self):
77+
square = Square()
78+
self.play(GrowFromEdge(square, DOWN))
79+
80+
81+
class SpinInFromNothingTest(Scene):
82+
def construct(self):
83+
square = Square()
84+
self.play(SpinInFromNothing(square))
85+
86+
87+
class ShrinkToCenterTest(Scene):
88+
def construct(self):
89+
square = Square()
90+
self.play(ShrinkToCenter(square))
91+
92+
def test_scenes(get_config_test):
93+
utils_test_scenes(get_scenes_to_test(__name__), get_config_test, "creation")

0 commit comments

Comments
 (0)