Skip to content

armgit / manim

Public Imported from GitHub
0

A community-maintained Python framework for creating mathematical animations.

Cleanup __main__.py - remove stray print statements (#1078)

Naveen M K0de873c803bc
diff --git a/manim/__main__.py b/manim/__main__.py
index 5863b592e..67bf2f613 100644
--- a/manim/__main__.py
+++ b/manim/__main__.py
@@ -81,13 +81,11 @@ def main():
server.start()
server.wait_for_termination()
except ModuleNotFoundError as e:
- print("\n\n")
- print(
+ console.print(
"Dependencies for the WebGL render are missing. Run "
"pip install manim[webgl_renderer] to install them."
)
- print(e)
- print("\n\n")
+ console.print_exception()
else:
for SceneClass in scene_classes_from_file(input_file):
try:
@@ -95,9 +93,7 @@ def main():
scene.render()
open_file_if_needed(scene.renderer.file_writer)
except Exception:
- print("\n\n")
- traceback.print_exc()
- print("\n\n")
+ console.print_exception()
if __name__ == "__main__":
diff --git a/manim/_config/main_utils.py b/manim/_config/main_utils.py
index aa7abcb2f..53419da56 100644
--- a/manim/_config/main_utils.py
+++ b/manim/_config/main_utils.py
@@ -111,7 +111,6 @@ def parse_args(args: list) -> argparse.Namespace:
elif subcmd == "plugins":
return _parse_args_plugins(args)
elif args[1] == "--version":
- print(f"Manim Community v{ __version__ }")
sys.exit()
# elif subcmd == some_other_future_subcmd:
# return _parse_args_some_other_subcmd(args)
diff --git a/tests/test_commands.py b/tests/test_commands.py
new file mode 100644
index 000000000..483f46b19
--- /dev/null
+++ b/tests/test_commands.py
@@ -0,0 +1,63 @@
+import subprocess
+import sys
+
+from .test_plugins.test_plugins import function_like_plugin
+
+import manim
+
+
+def call_command(command, cwd=None, env=None):
+ a = subprocess.run(
+ command,
+ stdout=subprocess.PIPE,
+ stderr=subprocess.PIPE,
+ check=True,
+ text=True,
+ cwd=cwd,
+ env=env,
+ )
+ return a
+
+
+def test_manim_version_from_command_line():
+ a = call_command(
+ [
+ sys.executable,
+ "-m",
+ "manim",
+ "--version",
+ ]
+ )
+ version = manim.__version__
+ assert version in a.stdout
+ assert a.stdout.strip() == f"Manim Community v{version}"
+
+
+def test_manim_cfg_subcommand_no_subcommand():
+ a = call_command(
+ [
+ sys.executable,
+ "-m",
+ "manim",
+ "cfg",
+ ]
+ )
+ assert "No subcommand provided; Exiting..." in a.stdout
+
+
+def test_manim_plugis_subcommand_no_subcommand():
+ a = call_command(
+ [
+ sys.executable,
+ "-m",
+ "manim",
+ "plugins",
+ ]
+ )
+ assert "No flag provided; Exiting..." in a.stdout
+
+
+def test_manim_plugis_subcommand_listing(function_like_plugin):
+ # Check whether `test_plugin` is in plugins list
+ a = call_command([sys.executable, "-m", "manim", "plugins", "--list"])
+ assert "test_plugin" in a.stdout