Repository: rtts/djhtml (language: python)

Issue:
Introduce "suite" of tests
It would be good if there were some test HTML files that show "input" vs "expected", allowing you to check if all the indenting logic is correct.


Discussion / hints:

Fix patch:
diff --git a/MANIFEST.in b/MANIFEST.in
new file mode 100644
index 0000000..8ba924e
--- /dev/null
+++ b/MANIFEST.in
@@ -0,0 +1,1 @@
+recursive-include djhtml *
diff --git a/setup.py b/setup.py
index 2b45d6b..f04fa01 100755
--- a/setup.py
+++ b/setup.py
@@ -6,7 +6,7 @@
 
 setuptools.setup(
     name="djhtml",
-    version="0.0.1",
+    version="0.0.2",
     author="Jaap Joris Vens",
     author_email="jj@rtts.eu",
     description="Django template indenter",
@@ -17,6 +17,7 @@
     entry_points={
         "console_scripts": ["djhtml=djhtml.__main__:main"],
     },
+    include_package_data=True,
     classifiers=[
         "Programming Language :: Python :: 3",
         "License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)",


Test patch:
diff --git a/djhtml/tests/__init__.py b/djhtml/tests/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/djhtml/tests/suite/minimal_html.in b/djhtml/tests/suite/minimal_html.in
new file mode 100644
index 0000000..3f8d1e9
--- /dev/null
+++ b/djhtml/tests/suite/minimal_html.in
@@ -0,0 +1,10 @@
+<html>
+<head>
+<title>Plain</title>
+<script src="test.js"></script>
+<link rel="stylesheet" href="test.css">
+</head>
+<body>
+<h1>Title</h1>
+</body>
+</html>
diff --git a/djhtml/tests/suite/minimal_html.out b/djhtml/tests/suite/minimal_html.out
new file mode 100644
index 0000000..3512e34
--- /dev/null
+++ b/djhtml/tests/suite/minimal_html.out
@@ -0,0 +1,10 @@
+<html>
+    <head>
+        <title>Plain</title>
+        <script src="test.js"></script>
+        <link rel="stylesheet" href="test.css">
+    </head>
+    <body>
+        <h1>Title</h1>
+    </body>
+</html>
diff --git a/djhtml/tests/test_suite.py b/djhtml/tests/test_suite.py
new file mode 100644
index 0000000..f9d3f65
--- /dev/null
+++ b/djhtml/tests/test_suite.py
@@ -0,0 +1,34 @@
+import os
+import unittest
+
+from djhtml.modes import HTML
+
+
+class TestSuite(unittest.TestCase):
+    DIR = os.path.join(os.path.dirname(__file__), "suite")
+
+    def test_available_files(self):
+        """
+        Loop over all the files in the suite directory and compare the
+        expected output to the actual output.
+
+        """
+        for filename in os.listdir(self.DIR):
+            with self.subTest(filename):
+                if filename.endswith(".in"):
+                    basename, _ = os.path.splitext(filename)
+                    with open(os.path.join(self.DIR, filename), "r") as f:
+                        inputfile = f.readlines()
+                    with open(os.path.join(self.DIR, f"{basename}.out"), "r") as f:
+                        expected_output = f.readlines()
+
+                    current_mode = HTML
+                    current_level = 0
+                    actual_output = []
+                    for line in inputfile:
+                        mode = current_mode(line.rstrip())
+                        actual_output.append(mode.get_line(current_level) + "\n")
+                        current_level += mode.nextlevel
+                        current_mode = mode.nextmode
+
+                    self.assertEqual(expected_output, actual_output)