Repository: ManimCommunity/manim

Issue:
Making test for SVGMobject
Here, I have some test and folder structure for SVGMobject and ImageMobject.
The images and svgs for the test can be found in a new folder called img_svg_resources

Depends on #650 


Discussion:

Resolving patch:
diff --git a/manim/mobject/types/image_mobject.py b/manim/mobject/types/image_mobject.py
--- a/manim/mobject/types/image_mobject.py
+++ b/manim/mobject/types/image_mobject.py
@@ -27,8 +27,7 @@ class AbstractImageMobject(Mobject):
     ----------
     scale_to_resolution : :class:`int`
         At this resolution the image is placed pixel by pixel onto the screen, so it will look the sharpest and best.
-        This is a custom parameter of ImageMobject so that rendering a scene with the `--quality low` flag for faster rendering and testing won't effect the position of the image on the screen.
-        Calculated by `height = image_height / scale_to_resolution * config["frame_height"]`
+        This is a custom parameter of ImageMobject so that rendering a scene with e.g. the ``--quality low`` or ``--quality medium`` flag for faster rendering won't effect the position of the image on the screen.
     """
 
     CONFIG = {
@@ -74,8 +73,7 @@ class ImageMobject(AbstractImageMobject):
         ----------
         scale_to_resolution : :class:`int`
             At this resolution the image is placed pixel by pixel onto the screen, so it will look the sharpest and best.
-            This is a custom parameter of ImageMobject so that rendering a scene with the `--quality low` flag for faster rendering and testing won't effect the position of the image on the screen.
-            Calculated by `height = image_height / scale_to_resolution * config["frame_height"]`
+            This is a custom parameter of ImageMobject so that rendering a scene with e.g. the ``--quality low`` or ``--quality medium`` flag for faster rendering won't effect the position of the image on the screen.
 
 
 


Test patch:
diff --git a/tests/control_data/graphical_units_data/img_and_svg/ImageMobjectTest.npz b/tests/control_data/graphical_units_data/img_and_svg/ImageMobjectTest.npz
new file mode 100644
Binary files /dev/null and b/tests/control_data/graphical_units_data/img_and_svg/ImageMobjectTest.npz differ
diff --git a/tests/control_data/graphical_units_data/img_and_svg/SVGMobjectTest.npz b/tests/control_data/graphical_units_data/img_and_svg/SVGMobjectTest.npz
new file mode 100644
Binary files /dev/null and b/tests/control_data/graphical_units_data/img_and_svg/SVGMobjectTest.npz differ
diff --git a/tests/helpers/path_utils.py b/tests/helpers/path_utils.py
new file mode 100644
--- /dev/null
+++ b/tests/helpers/path_utils.py
@@ -0,0 +1,5 @@
+from pathlib import Path
+
+
+def get_project_root() -> Path:
+    return Path(__file__).parent.parent.parent
diff --git a/tests/test_graphical_units/img_svg_resources/tree_img_640x351.png b/tests/test_graphical_units/img_svg_resources/tree_img_640x351.png
new file mode 100644
Binary files /dev/null and b/tests/test_graphical_units/img_svg_resources/tree_img_640x351.png differ
diff --git a/tests/test_graphical_units/img_svg_resources/weight.svg b/tests/test_graphical_units/img_svg_resources/weight.svg
new file mode 100644
--- /dev/null
+++ b/tests/test_graphical_units/img_svg_resources/weight.svg
@@ -0,0 +1,175 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<svg
+   xmlns:dc="http://purl.org/dc/elements/1.1/"
+   xmlns:cc="http://creativecommons.org/ns#"
+   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
+   xmlns:svg="http://www.w3.org/2000/svg"
+   xmlns="http://www.w3.org/2000/svg"
+   xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
+   xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
+   sodipodi:docname="weight.svg"
+   inkscape:version="1.0 (6e3e5246a0, 2020-05-07)"
+   id="svg8"
+   version="1.1"
+   viewBox="0 0 112.95123 196.64897"
+   height="196.64897mm"
+   width="112.95123mm">
+  <defs
+     id="defs2">
+    <inkscape:path-effect
+       effect="bspline"
+       id="path-effect253"
+       is_visible="true"
+       lpeversion="1"
+       weight="33.333333"
+       steps="2"
+       helper_size="0"
+       apply_no_weight="true"
+       apply_with_weight="true"
+       only_selected="false" />
+    <inkscape:path-effect
+       effect="bspline"
+       id="path-effect251"
+       is_visible="true"
+       lpeversion="1"
+       weight="33.333333"
+       steps="2"
+       helper_size="0"
+       apply_no_weight="true"
+       apply_with_weight="true"
+       only_selected="false" />
+    <inkscape:path-effect
+       effect="bspline"
+       id="path-effect249"
+       is_visible="true"
+       lpeversion="1"
+       weight="33.333333"
+       steps="2"
+       helper_size="0"
+       apply_no_weight="true"
+       apply_with_weight="true"
+       only_selected="false" />
+    <inkscape:path-effect
+       effect="bspline"
+       id="path-effect247"
+       is_visible="true"
+       lpeversion="1"
+       weight="33.333333"
+       steps="2"
+       helper_size="0"
+       apply_no_weight="true"
+       apply_with_weight="true"
+       only_selected="false" />
+    <inkscape:path-effect
+       effect="bspline"
+       id="path-effect245"
+       is_visible="true"
+       lpeversion="1"
+       weight="33.333333"
+       steps="2"
+       helper_size="0"
+       apply_no_weight="true"
+       apply_with_weight="true"
+       only_selected="false" />
+    <inkscape:path-effect
+       effect="bspline"
+       id="path-effect243"
+       is_visible="true"
+       lpeversion="1"
+       weight="33.333333"
+       steps="2"
+       helper_size="0"
+       apply_no_weight="true"
+       apply_with_weight="true"
+       only_selected="false" />
+    <inkscape:path-effect
+       only_selected="false"
+       apply_with_weight="true"
+       apply_no_weight="true"
+       helper_size="0"
+       steps="2"
+       weight="33.333333"
+       lpeversion="1"
+       is_visible="true"
+       id="path-effect103"
+       effect="bspline" />
+    <inkscape:path-effect
+       only_selected="false"
+       apply_with_weight="true"
+       apply_no_weight="true"
+       helper_size="0"
+       steps="2"
+       weight="33.333333"
+       lpeversion="1"
+       is_visible="true"
+       id="path-effect99"
+       effect="bspline" />
+    <inkscape:path-effect
+       only_selected="false"
+       apply_with_weight="true"
+       apply_no_weight="true"
+       helper_size="0"
+       steps="2"
+       weight="33.333333"
+       lpeversion="1"
+       is_visible="true"
+       id="path-effect95"
+       effect="bspline" />
+    <inkscape:path-effect
+       only_selected="false"
+       apply_with_weight="true"
+       apply_no_weight="true"
+       helper_size="0"
+       steps="2"
+       weight="33.333333"
+       lpeversion="1"
+       is_visible="true"
+       id="path-effect91"
+       effect="bspline" />
+    <inkscape:path-effect
+       only_selected="false"
+       apply_with_weight="true"
+       apply_no_weight="true"
+       helper_size="0"
+       steps="2"
+       weight="33.333333"
+       lpeversion="1"
+       is_visible="true"
+       id="path-effect79"
+       effect="bspline" />
+    <inkscape:path-effect
+       only_selected="false"
+       apply_with_weight="true"
+       apply_no_weight="true"
+       helper_size="0"
+       steps="2"
+       weight="33.333333"
+       lpeversion="1"
+       is_visible="true"
+       id="path-effect75"
+       effect="bspline" />
+  </defs>
+  <metadata
+     id="metadata5">
+    <rdf:RDF>
+      <cc:Work
+         rdf:about="">
+        <dc:format>image/svg+xml</dc:format>
+        <dc:type
+           rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
+        <dc:title></dc:title>
+      </cc:Work>
+    </rdf:RDF>
+  </metadata>
+  <g
+     style="display:inline"
+     transform="translate(-42.767119,-68.460435)"
+     id="layer1"
+     inkscape:groupmode="layer"
+     inkscape:label="Layer 1">
+    <path
+       id="path276"
+       d="m 67.713129,264.63459 c -5.22882,-0.71795 -10.56064,-2.02283 -15.76228,-3.85758 -5.0911,-1.79576 -7.47174,-3.12962 -8.45047,-4.73475 -0.71446,-1.17174 -0.73088,-2.56044 -0.73226,-61.93255 l -10e-4,-60.73393 1.06899,-0.76119 c 1.6018,-1.14057 5.92943,-2.95785 17.64084,-7.40779 5.82083,-2.21172 11.80116,-4.60584 13.28963,-5.32028 3.04604,-1.46203 5.64223,-4.04806 5.99989,-5.9764 0.12093,-0.65204 0.16754,-5.38186 0.10357,-10.51072 l -0.11631,-9.325194 -0.93533,-0.994871 c -0.51443,-0.547179 -3.04793,-2.203264 -5.62999,-3.680189 -2.58207,-1.476925 -5.2653,-3.186339 -5.96274,-3.798697 -1.2402,-1.088913 -1.26807,-1.179788 -1.26807,-4.135404 0,-3.725264 0.56974,-5.040688 3.16816,-7.314757 2.22096,-1.943728 7.02462,-4.39811 10.06101,-5.140569 3.00192,-0.734032 35.188441,-0.731654 38.175591,0.0028 5.07692,1.248301 11.5406,5.439635 12.7119,8.242951 0.29288,0.700954 0.51727,2.562803 0.51727,4.291987 0,3.759929 0.0272,3.729697 -6.97673,7.740452 -7.41893,4.248372 -6.79769,2.967809 -6.93289,14.290711 -0.12879,10.78582 0.0423,11.73077 2.53123,13.97936 1.95237,1.76385 4.66376,2.98331 17.5153,7.87758 11.86135,4.51717 16.82531,6.65787 17.5845,7.5833 0.37906,0.46206 0.45596,13.01775 0.37797,61.71814 l -0.0979,61.13807 -1.45472,1.25748 c -2.69141,2.32649 -11.35127,5.36658 -20.08993,7.05267 -3.98413,0.76873 -5.37299,0.80624 -33.2619,0.89825 -23.668361,0.0781 -29.845411,-0.006 -33.072921,-0.4489 z"
+       style="fill:#a0a0a0;stroke:none;stroke-width:0.377976" />
+  </g>
+</svg>
diff --git a/tests/test_graphical_units/test_img_and_svg.py b/tests/test_graphical_units/test_img_and_svg.py
new file mode 100644
--- /dev/null
+++ b/tests/test_graphical_units/test_img_and_svg.py
@@ -0,0 +1,44 @@
+import sys
+from pathlib import Path
+
+import pytest
+from manim import *
+from ..helpers.path_utils import get_project_root
+from ..utils.testing_utils import get_scenes_to_test
+from ..utils.GraphicalUnitTester import GraphicalUnitTester
+
+# Tests for the modules image_mobject and svg_mobject
+
+
+class SVGMobjectTest(Scene):
+    def construct(self):
+        path = (
+            get_project_root()
+            / "tests/test_graphical_units/img_svg_resources/weight.svg"
+        )
+        svg_obj = SVGMobject(str(path))
+        self.add(svg_obj)
+        self.wait()
+
+
+class ImageMobjectTest(Scene):
+    def construct(self):
+        file_path = (
+            get_project_root()
+            / "tests/test_graphical_units/img_svg_resources/tree_img_640x351.png"
+        )
+        im1 = ImageMobject(file_path).shift(4 * LEFT + UP)
+        im2 = ImageMobject(file_path, scale_to_resolution=1080).shift(
+            4 * LEFT + 2 * DOWN
+        )
+        im3 = ImageMobject(file_path, scale_to_resolution=540).shift(4 * RIGHT)
+        self.add(im1, im2, im3)
+        self.wait(1)
+
+
+MODULE_NAME = "img_and_svg"
+
+
+@pytest.mark.parametrize("scene_to_test", get_scenes_to_test(__name__), indirect=False)
+def test_scene(scene_to_test, tmpdir, show_diff):
+    GraphicalUnitTester(scene_to_test[1], MODULE_NAME, tmpdir).test(show_diff=show_diff)