diff options
author | 2024-01-18 13:36:57 +0500 | |
---|---|---|
committer | 2024-03-31 01:09:56 +0100 | |
commit | 9e27e7345e303a024ab58aa197727c5620843b12 (patch) | |
tree | 083c67a49ea3a4218ca157d8a71a44a2fbf08485 | |
parent | Switch from setup.py to PEP517 (diff) | |
download | metagen-9e27e7345e303a024ab58aa197727c5620843b12.tar.gz metagen-9e27e7345e303a024ab58aa197727c5620843b12.tar.bz2 metagen-9e27e7345e303a024ab58aa197727c5620843b12.zip |
Add real unit tests
Signed-off-by: Sebastian Pipping <sping@gentoo.org>
-rw-r--r-- | metagen/meta_unittest.py | 24 | ||||
-rw-r--r--[-rwxr-xr-x] | metagen/metagenerator.py | 19 | ||||
-rw-r--r-- | metagen/tests/__init__.py | 0 | ||||
-rw-r--r-- | metagen/tests/test_meta.py | 60 |
4 files changed, 60 insertions, 43 deletions
diff --git a/metagen/meta_unittest.py b/metagen/meta_unittest.py deleted file mode 100644 index d54236a..0000000 --- a/metagen/meta_unittest.py +++ /dev/null @@ -1,24 +0,0 @@ -#!/usr/bin/python3 - -from .metagenerator import MyMetadata - - -def test1(): - """1 maintainer""" - metadata = MyMetadata() - metadata.set_maintainer(["<pythonhead@gentoo.org>"], - ["Rob Cakebread"], - ["Maintainer description."], - ["person"]) - return metadata - -def test2(): - """2 maintainers, longdesc""" - metadata = MyMetadata() - metadata.set_maintainer(["goofy@gentoo.org", "pythonhead@gentoo.org"], - ["Goo Fi", "Rob Cakebread"], - ["Maintainer one.", "Maintainer two"], - ["person", "person"]) - metadata.set_longdescription("This packages does X Y and Z.") - return metadata - diff --git a/metagen/metagenerator.py b/metagen/metagenerator.py index 862df8c..d0403fa 100755..100644 --- a/metagen/metagenerator.py +++ b/metagen/metagenerator.py @@ -82,22 +82,3 @@ class MyMetadata: # - to make pkgcheck stop from warning about PkgMetadataXmlIndentation return xml_text.replace('<!DOCTYPE pkgmetadata\n SYSTEM', '<!DOCTYPE pkgmetadata SYSTEM') - - -def do_tests(): - from metagen import meta_unittest - fails = 0 - for func in dir(meta_unittest): - if func[0:4] == "test": - try: - exec("print(meta_unittest.%s.__name__ + ':', end='')" % func) - exec("print(meta_unittest.%s.__doc__)" % func) - exec("print(meta_unittest.%s())" % func) - except: - fails += 1 - print("Test %s failed:" % func) - print(sys.exc_info()[0], sys.exc_info()[1]) - print("%s tests failed." % fails) - -if __name__ == "__main__": - do_tests() diff --git a/metagen/tests/__init__.py b/metagen/tests/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/metagen/tests/__init__.py diff --git a/metagen/tests/test_meta.py b/metagen/tests/test_meta.py new file mode 100644 index 0000000..e692eb5 --- /dev/null +++ b/metagen/tests/test_meta.py @@ -0,0 +1,60 @@ +import textwrap +import unittest + +from metagen.metagenerator import MyMetadata + + +class TestMyMetadata(unittest.TestCase): + + maxDiff = 1500 + + def test_simple(self): + expected = textwrap.dedent( + """ + <?xml version="1.0" encoding="UTF-8"?> + <!DOCTYPE pkgmetadata SYSTEM 'https://www.gentoo.org/dtd/metadata.dtd'> + <pkgmetadata> + \t<maintainer type="person"> + \t\t<email>pythonhead@gentoo.org</email> + \t\t<name>Rob Cakebread</name> + \t\t<description>Maintainer description.</description> + \t</maintainer> + </pkgmetadata> + """.strip("\n") + ) + + metadata = MyMetadata() + metadata.set_maintainer(["pythonhead@gentoo.org"], + ["Rob Cakebread"], + ["Maintainer description."], + ["person"]) + self.assertEqual(str(metadata), expected) + + def test_long(self): + expected = textwrap.dedent( + """ + <?xml version="1.0" encoding="UTF-8"?> + <!DOCTYPE pkgmetadata SYSTEM 'https://www.gentoo.org/dtd/metadata.dtd'> + <pkgmetadata> + \t<maintainer type="person"> + \t\t<email>goofy@gentoo.org</email> + \t\t<name>Goo Fi</name> + \t\t<description>Maintainer one.</description> + \t</maintainer> + \t<maintainer type="person"> + \t\t<email>pythonhead@gentoo.org</email> + \t\t<name>Rob Cakebread</name> + \t\t<description>Maintainer two</description> + \t</maintainer> + \t<longdescription>This packages does X Y and Z.</longdescription> + </pkgmetadata> + """.strip("\n") + ) + + metadata = MyMetadata() + metadata.set_maintainer(["goofy@gentoo.org", "pythonhead@gentoo.org"], + ["Goo Fi", "Rob Cakebread"], + ["Maintainer one.", "Maintainer two"], + ["person", "person"]) + metadata.set_longdescription("This packages does X Y and Z.") + self.assertEqual(str(metadata), expected) |