Skip to content

armgit / manim

Public Imported from GitHub
0

A community-maintained Python framework for creating mathematical animations.

Change directory in subprocess instead of in test.

Aathish9018eaa02043
diff --git a/tests/test_cli/test_cfg_subcmd.py b/tests/test_cli/test_cfg_subcmd.py
index 2d88f4b0d..5c2b0672a 100644
--- a/tests/test_cli/test_cfg_subcmd.py
+++ b/tests/test_cli/test_cfg_subcmd.py
@@ -3,35 +3,35 @@ import os
import shutil
from test_cli import capture
+this_folder = os.path.dirname(__file__)
def test_cfg_help(python_version):
"""Test if Manim successfully adds configparsers when a subcommand is invoked."""
- os.chdir(os.path.dirname(__file__))
- command = [python_version, "-m", "manim", "cfg", "--help"]
- out, err, exitcode = capture(command)
+ command = f"cd {this_folder} && {python_version} -m manim cfg --help"
+ out, err, exitcode = capture(command, use_shell=True)
assert exitcode == 0, f"The cfg subcommand is not working as intended."
def test_cfg_show(python_version):
"""Test if the `manim cfg show` command works as intended."""
- command = [python_version, "-m", "manim", "cfg", "show"]
- out, err, exitcode = capture(command)
+ command = f"cd {this_folder} && {python_version} -m manim cfg show"
+ out, err, exitcode = capture(command, use_shell=True)
assert exitcode == 0
assert f"{os.path.sep}tests{os.path.sep}".encode("utf-8") in out, err
def test_cfg_export(python_version):
"""Test if the `manim cfg export` command works as intended."""
- command = [python_version, "-m", "manim", "cfg", "export", "--dir", "temp"]
- out, err, exitcode = capture(command)
+ command = f"cd {this_folder} && {python_version} -m manim cfg export --dir temp"
+ out, err, exitcode = capture(command, use_shell=True)
assert exitcode == 0
- assert os.path.exists(os.path.join("temp","manim.cfg"))
- with open(os.path.join("temp","manim.cfg"),"r") as writtencfg:
+ assert os.path.exists(os.path.join(this_folder,"temp","manim.cfg"))
+ with open(os.path.join(this_folder,"temp","manim.cfg"),"r") as writtencfg:
assert "sound = True" in writtencfg.read(), err
- shutil.rmtree("temp")
+ shutil.rmtree(os.path.join(this_folder,"temp"))
def test_cfg_write(python_version):
"""Simulate using the command `manim cfg write`"""
- cfgfilepath = os.path.join(os.path.dirname(__file__), "manim.cfg")
- command = [python_version, "-m", "manim","cfg","write","--level","cwd"]
+ cfgfilepath = os.path.join(this_folder, "manim.cfg")
+ command = f"cd {this_folder} && {python_version} -m manim cfg write --level cwd"
"""As the number of config values that `manim cfg write` can modify increases, so
must the number of newlines and/or values written in write_cfg_sbcmd_input increase."""
@@ -40,7 +40,8 @@ def test_cfg_write(python_version):
out, err, exitcode = capture(
command,
- open(os.path.join(os.path.dirname(__file__), "write_cfg_sbcmd_input.txt"))
+ instream=open(os.path.join(this_folder, "write_cfg_sbcmd_input.txt")),
+ use_shell=True
)
assert exitcode == 0, err
@@ -49,4 +50,3 @@ def test_cfg_write(python_version):
with open(cfgfilepath,"w") as cfgfile:
cfgfile.write(original)
- os.chdir(os.path.abspath(os.path.join(__file__, os.pardir, os.pardir, os.pardir)))
\ No newline at end of file
diff --git a/tests/test_cli/test_cli.py b/tests/test_cli/test_cli.py
index 0da7fa9bc..11a7e7c63 100644
--- a/tests/test_cli/test_cli.py
+++ b/tests/test_cli/test_cli.py
@@ -4,11 +4,12 @@ from shutil import rmtree
import pytest
-def capture(command,instream=None):
+def capture(command,instream=None, use_shell=False):
proc = subprocess.Popen(command,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
- stdin=instream
+ stdin=instream,
+ shell = use_shell
)
out, err = proc.communicate()
return out, err, proc.returncode
@@ -49,7 +50,7 @@ def test_dash_as_name(python_version):
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"))
+ instream = open(os.path.join(os.path.dirname(__file__), "dash_test_script.txt"))
)
assert exitcode == 0, err
assert os.path.exists(os.path.join(