Skip to content

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

Merged
merged 60 commits into from
Jun 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
4f9b9bb
added set_test
huguesdevimeux Jun 2, 2020
5f313ae
added conftest file
huguesdevimeux Jun 2, 2020
e483a53
updated caching configuration
huguesdevimeux Jun 3, 2020
30776ef
added tests
huguesdevimeux Jun 3, 2020
29efd9c
fixed test_CLI
huguesdevimeux Jun 3, 2020
063202f
added cached data
huguesdevimeux Jun 3, 2020
3451752
added test data
huguesdevimeux Jun 3, 2020
d310caf
deleted test_sample_scene (useless)
huguesdevimeux Jun 4, 2020
abb220d
fixed conftest
huguesdevimeux Jun 4, 2020
95ae968
now it should work
huguesdevimeux Jun 4, 2020
f39ef13
Revert "fixed conftest"
huguesdevimeux Jun 4, 2020
3e90eea
Ok so now it should work
huguesdevimeux Jun 4, 2020
572d881
updated TextMobject and fixed WriteTest
huguesdevimeux Jun 4, 2020
8955f34
debuging Travis
huguesdevimeux Jun 5, 2020
09b18f9
travis 1 - 0 me
huguesdevimeux Jun 5, 2020
dfcc8c3
install ffmpeg and tex in linux
huguesdevimeux Jun 5, 2020
c51bd07
specfied font for the Text Test
huguesdevimeux Jun 5, 2020
df6f2d2
changing python version
huguesdevimeux Jun 5, 2020
1a23c72
install ffmpeg and latex on osx
huguesdevimeux Jun 5, 2020
259bba3
Merge branch 'master' into testings
huguesdevimeux Jun 8, 2020
b312320
added latex to the path in osx
huguesdevimeux Jun 8, 2020
7afa989
changed python3 to python (test)
huguesdevimeux Jun 8, 2020
4d937d7
changed python version dynamically
huguesdevimeux Jun 9, 2020
62fe97f
added latex installation on windows
huguesdevimeux Jun 9, 2020
88200df
Merge branch 'master' into testings
huguesdevimeux Jun 9, 2020
40f997f
fixed latex installaation on windows
huguesdevimeux Jun 9, 2020
25a9434
fixed miktexsetup path on windows
huguesdevimeux Jun 9, 2020
f58fb85
added -f to curl on windows
huguesdevimeux Jun 9, 2020
c746120
added comment on TexMobjectTest
huguesdevimeux Jun 15, 2020
014dbb0
Merge branch 'master' into testings
huguesdevimeux Jun 15, 2020
1ad7143
added --skip_to_end flag to pytest wind
huguesdevimeux Jun 15, 2020
b38d00a
Deleting latex and ffmpeg installation on windows
huguesdevimeux Jun 15, 2020
349ec04
added -rs flag to show details of the skippedtests
huguesdevimeux Jun 15, 2020
f1d8da3
removed WriteTest (see issue #157)
huguesdevimeux Jun 17, 2020
9f645d0
added comments
huguesdevimeux Jun 17, 2020
7fdba8e
fixed typo
huguesdevimeux Jun 17, 2020
0dfd8cc
delted useless parameter
huguesdevimeux Jun 19, 2020
55c9899
deleted useless import
huguesdevimeux Jun 19, 2020
67241f6
moved set_test_scene to tests/utils
huguesdevimeux Jun 19, 2020
c756d45
renames tests/utils to tests/testing_utils
huguesdevimeux Jun 19, 2020
22b408b
added test_graph (data and cache)
huguesdevimeux Jun 19, 2020
0752ef0
fixed typo
huguesdevimeux Jun 19, 2020
11144c5
fixed typo and wording
huguesdevimeux Jun 19, 2020
7b5f0a9
removed useless return
huguesdevimeux Jun 19, 2020
217f6b0
minor syntax improvement
huguesdevimeux Jun 19, 2020
de21699
improved verbose
huguesdevimeux Jun 19, 2020
7690ed7
minor syntax improvement
huguesdevimeux Jun 19, 2020
420aae2
minor syntax improvements
huguesdevimeux Jun 19, 2020
2a6c276
updated basi_scenes.py [skip ci]
huguesdevimeux Jun 19, 2020
85291ba
used logging instead of print
huguesdevimeux Jun 20, 2020
c4ed7f2
refactored test code architecture
huguesdevimeux Jun 20, 2020
24955eb
improved comments
huguesdevimeux Jun 20, 2020
b83ab84
adde linux.sh to shorten travis.yml
huguesdevimeux Jun 20, 2020
13c765d
Update tests/test_CLI.py
huguesdevimeux Jun 21, 2020
a963965
Apply suggestions from code review [skip ci]
huguesdevimeux Jun 21, 2020
4f4aba1
Update tests/test_graph.py [skip ci]
huguesdevimeux Jun 21, 2020
21438ae
removed damn blank lines
huguesdevimeux Jun 22, 2020
ade21ea
Merge branch 'testings' of https://github.com/huguesdevimeux/manim in…
huguesdevimeux Jun 22, 2020
4a553e1
updated comments so it fits guidelines [skip ci]
huguesdevimeux Jun 22, 2020
7f28eb6
fixed minor typo [skip ci]
huguesdevimeux Jun 22, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 20 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Copy link

@hadichaudhri hadichaudhri Jun 20, 2020

Choose a reason for hiding this comment

The 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 .bat script to set up the environment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment was supposed to be 3 lines up in before-install, but you get the gist.


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
Expand Down
5 changes: 5 additions & 0 deletions .travis/linux.sh
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
63 changes: 63 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
from manim import dirs
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
46 changes: 46 additions & 0 deletions tests/test_CLI.py
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)
93 changes: 93 additions & 0 deletions tests/test_creation.py
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)

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")
Loading