summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2020-03-16 21:18:18 +0100
committerSebastian Huber <sebastian.huber@embedded-brains.de>2020-03-16 21:18:18 +0100
commit823c74c5d68a5b0913eba2bd9202897cb883dcef (patch)
treedc6905a1e53b1dcf03772335921fdb4859383cf3
parentd854464c19b5a6adf7300d47c8acafa63524f217 (diff)
Convert content test to pytest
-rw-r--r--tests/test_content.py99
1 files changed, 49 insertions, 50 deletions
diff --git a/tests/test_content.py b/tests/test_content.py
index de3221f3..6e9dafeb 100644
--- a/tests/test_content.py
+++ b/tests/test_content.py
@@ -24,8 +24,7 @@
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
-import tempfile
-import unittest
+import pytest
from rtemsqual.content import Copyright
from rtemsqual.content import Copyrights
@@ -34,38 +33,39 @@ from rtemsqual.content import MacroToSphinx
from rtemsqual.items import Item
-class TestCopyright(unittest.TestCase):
+class TestCopyright(object):
def test_get_statement(self):
c = Copyright("John Doe")
- self.assertEqual("Copyright (C) John Doe", c.get_statement())
+ assert "Copyright (C) John Doe" == c.get_statement()
c.add_year("3")
- self.assertEqual("Copyright (C) 3 John Doe", c.get_statement())
+ assert "Copyright (C) 3 John Doe" == c.get_statement()
c.add_year("3")
- self.assertEqual("Copyright (C) 3 John Doe", c.get_statement())
+ assert "Copyright (C) 3 John Doe" == c.get_statement()
c.add_year("5")
- self.assertEqual("Copyright (C) 3, 5 John Doe", c.get_statement())
+ assert "Copyright (C) 3, 5 John Doe" == c.get_statement()
c.add_year("4")
- self.assertEqual("Copyright (C) 3, 5 John Doe", c.get_statement())
+ assert "Copyright (C) 3, 5 John Doe" == c.get_statement()
c.add_year("2")
- self.assertEqual("Copyright (C) 2, 5 John Doe", c.get_statement())
+ assert "Copyright (C) 2, 5 John Doe" == c.get_statement()
def test_lt(self):
a = Copyright("A")
b = Copyright("B")
c = Copyright("C")
- self.assertLess(b, a)
- self.assertLess(c, a)
- self.assertLess(c, b)
+ assert b < a
+ assert c < a
+ assert c < b
b.add_year("1")
- self.assertLess(b, c)
+ assert b < c
a.add_year("2")
- self.assertLess(a, b)
+ assert a < b
-class TestCopyrights(unittest.TestCase):
+class TestCopyrights(object):
def test_register(self):
c = Copyrights()
- self.assertRaises(ValueError, c.register, "abc")
+ with pytest.raises(ValueError):
+ c.register("abc")
c.register("Copyright (C) A")
c.register("Copyright (C) 2 A")
c.register("Copyright (C) 2, 3 A")
@@ -75,78 +75,76 @@ class TestCopyrights(unittest.TestCase):
c.register("Copyright (C) C")
c.register("Copyright (C) 1 B")
s = c.get_statements()
- self.assertEqual(4, len(s))
- self.assertEqual("Copyright (C) C", s[0])
- self.assertEqual("Copyright (C) 2, 3 A", s[1])
- self.assertEqual("Copyright (C) 1, 4 D", s[2])
- self.assertEqual("Copyright (C) 1 B", s[3])
+ assert 4 == len(s)
+ assert "Copyright (C) C" == s[0]
+ assert "Copyright (C) 2, 3 A" == s[1]
+ assert "Copyright (C) 1, 4 D" == s[2]
+ assert "Copyright (C) 1 B" == s[3]
-class TestSphinxContent(unittest.TestCase):
+class TestSphinxContent(object):
def test_add_label(self):
sc = SphinxContent()
sc.add_label("x")
- self.assertEqual(".. _x:\n", sc.content)
+ assert ".. _x:\n" == sc.content
def test_add_header(self):
sc = SphinxContent()
sc.add_header("x")
- self.assertEqual("x\n=\n", sc.content)
+ assert "x\n=\n" == sc.content
def test_add_blank_line(self):
sc = SphinxContent()
sc.add_blank_line()
- self.assertEqual("\n", sc.content)
+ assert "\n" == sc.content
def test_add_line(self):
sc = SphinxContent()
sc.add_line("x")
- self.assertEqual("x\n", sc.content)
+ assert "x\n" == sc.content
sc.add_line("y", 1)
- self.assertEqual("x\n y\n", sc.content)
+ assert "x\n y\n" == sc.content
sc.add_line("")
- self.assertEqual("x\n y\n\n", sc.content)
+ assert "x\n y\n\n" == sc.content
def test_add_index_entries(self):
sc = SphinxContent()
sc.add_index_entries(["x", "y"])
- self.assertEqual("\n.. index:: x\n.. index:: y\n", sc.content)
+ assert "\n.. index:: x\n.. index:: y\n", sc.content
def test_add_definition_item(self):
sc = SphinxContent()
sc.add_definition_item("x", ["y", "z"])
- self.assertEqual("\nx\n y\n z\n", sc.content)
+ assert "\nx\n y\n z\n" == sc.content
def test_license(self):
sc = SphinxContent()
- self.assertRaises(ValueError, sc.register_license, "x")
+ with pytest.raises(ValueError):
+ sc.register_license("x")
sc.register_license("CC-BY-SA-4.0")
- self.assertEqual("", sc.content)
+ assert "" == sc.content
sc.add_licence_and_copyrights()
- self.assertEqual(".. SPDX-License-Identifier: CC-BY-SA-4.0\n\n",
- sc.content)
+ assert ".. SPDX-License-Identifier: CC-BY-SA-4.0\n\n" == sc.content
def test_license_and_copyrights(self):
sc = SphinxContent()
- self.assertRaises(ValueError, sc.register_license, "x")
+ with pytest.raises(ValueError):
+ sc.register_license("x")
sc.register_copyright("Copyright (C) A")
- self.assertEqual("", sc.content)
+ assert "" == sc.content
sc.add_licence_and_copyrights()
- self.assertEqual(
- ".. SPDX-License-Identifier: CC-BY-SA-4.0\n\n.. Copyright (C) A\n\n",
- sc.content)
+ assert ".. SPDX-License-Identifier: CC-BY-SA-4.0\n\n.. Copyright (C) A\n\n" == sc.content
- def test_write(self):
+ def test_write(self, tmpdir):
sc = SphinxContent()
sc.add_line("x")
- with tempfile.TemporaryDirectory() as tempdir:
- path = tempdir + "/y/z"
- sc.write(path)
- with open(path, "r") as src:
- self.assertEqual("x\n", src.read())
+ path = tmpdir + "/y/z"
+ sc.write(path)
+ with open(path, "r") as src:
+ assert "x\n" == src.read()
-class TestMacroToSphinx(unittest.TestCase):
+class TestMacroToSphinx(object):
def test_substitute(self):
macro_to_sphinx = MacroToSphinx()
data = {}
@@ -154,7 +152,8 @@ class TestMacroToSphinx(unittest.TestCase):
terms = {}
terms["x"] = Item("x", data)
macro_to_sphinx.set_terms(terms)
- self.assertEqual("@", macro_to_sphinx.substitute("@@"))
- self.assertEqual("@x", macro_to_sphinx.substitute("@x"))
- self.assertRaises(KeyError, macro_to_sphinx.substitute, "@x{y}")
- self.assertEqual(":term:`y`", macro_to_sphinx.substitute("@term{x}"))
+ assert "@" == macro_to_sphinx.substitute("@@")
+ assert "@x" == macro_to_sphinx.substitute("@x")
+ with pytest.raises(KeyError):
+ macro_to_sphinx.substitute("@x{y}")
+ assert ":term:`y`" == macro_to_sphinx.substitute("@term{x}")