Skip to content

Commit

Permalink
Merge pull request #203 from Aathish04/fix-dash-as-filename
Browse files Browse the repository at this point in the history
Allow the user to type manim code when using - as filename.
  • Loading branch information
leotrs authored Jul 15, 2020
2 parents 8c8de97 + 7cd6216 commit 79aa3d1
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
6 changes: 6 additions & 0 deletions manim/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import re
import traceback
import importlib.util
import types

from .config import file_writer_config
from .scene.scene import Scene
Expand Down Expand Up @@ -123,7 +124,12 @@ def get_scene_classes_from_module(module):
def get_module(file_name):
if file_name == "-":
module = types.ModuleType("input_scenes")
logger.info("Enter the animation's code & end with an EOF (CTRL+D on Linux/Unix, CTRL+Z on Windows):")
code = sys.stdin.read()
if not code.startswith("from manim import"):
logger.warn("Didn't find an import statement for Manim. Importing automatically...")
code="from manim import *\n"+code
logger.info("Rendering animation from typed code...")
try:
exec(code, module.__dict__)
return module
Expand Down
5 changes: 5 additions & 0 deletions tests/test_cli/dash_test_script.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# from manim import *
class Dash_Test(Scene):
def construct(self):
self.play(ReplacementTransform(Square(),Circle()))
self.wait(2)
17 changes: 16 additions & 1 deletion tests/test_cli/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
import pytest


def capture(command):
def capture(command,instream=None):
proc = subprocess.Popen(command,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
stdin=instream
)
out, err = proc.communicate()
return out, err, proc.returncode
Expand Down Expand Up @@ -44,3 +45,17 @@ def test_WriteStuff(python_version):
assert os.path.exists(os.path.join(
path_output, "videos", "basic_scenes", "480p15", "WriteStuff.mp4")), err
rmtree(path_output)

@pytest.mark.skip_end_to_end
def test_dash_as_name(python_version):
"""Simulate using - as a filename. Intended to test the feature that allows end users to type manim code on the spot."""
path_output = os.path.join("tests_cache", "media_temp")
command = [python_version, "-m", "manim", "-", "-l", "--media_dir", path_output]
out, err, exitcode = capture(
command,
open(os.path.join(os.path.dirname(__file__), "dash_test_script.txt"))
)
assert exitcode == 0, err
assert os.path.exists(os.path.join(
path_output, "videos", "-", "480p15", "Dash_Test.mp4")), err
rmtree(path_output)

0 comments on commit 79aa3d1

Please sign in to comment.