summaryrefslogtreecommitdiffstats
path: root/contrib/tools/cython/Cython/Tests/TestTestUtils.py
diff options
context:
space:
mode:
authornik-bes <[email protected]>2025-05-19 07:20:13 +0300
committernik-bes <[email protected]>2025-05-19 07:36:02 +0300
commit317b7368e24941ff76499f500579fd9b10f6656e (patch)
treeabbcbaea595e7d2e9f23cf59a408b3082fe4340d /contrib/tools/cython/Cython/Tests/TestTestUtils.py
parent6b666a52d40308ab9b3532cd8d3008b9f37cfffb (diff)
Update Cython to 3.0.10.
commit_hash:b43c96b868cd36d636192fd2c6024d9f0d2fb6f8
Diffstat (limited to 'contrib/tools/cython/Cython/Tests/TestTestUtils.py')
-rw-r--r--contrib/tools/cython/Cython/Tests/TestTestUtils.py92
1 files changed, 92 insertions, 0 deletions
diff --git a/contrib/tools/cython/Cython/Tests/TestTestUtils.py b/contrib/tools/cython/Cython/Tests/TestTestUtils.py
new file mode 100644
index 00000000000..e8329188b31
--- /dev/null
+++ b/contrib/tools/cython/Cython/Tests/TestTestUtils.py
@@ -0,0 +1,92 @@
+# -*- coding: utf-8 -*-
+
+import os.path
+import unittest
+import tempfile
+import textwrap
+import shutil
+
+from ..TestUtils import write_file, write_newer_file, _parse_pattern
+
+
+class TestTestUtils(unittest.TestCase):
+ def setUp(self):
+ super(TestTestUtils, self).setUp()
+ self.temp_dir = tempfile.mkdtemp()
+
+ def tearDown(self):
+ if self.temp_dir and os.path.isdir(self.temp_dir):
+ shutil.rmtree(self.temp_dir)
+ super(TestTestUtils, self).tearDown()
+
+ def _test_path(self, filename):
+ return os.path.join(self.temp_dir, filename)
+
+ def _test_write_file(self, content, expected, **kwargs):
+ file_path = self._test_path("abcfile")
+ write_file(file_path, content, **kwargs)
+ assert os.path.isfile(file_path)
+
+ with open(file_path, 'rb') as f:
+ found = f.read()
+ assert found == expected, (repr(expected), repr(found))
+
+ def test_write_file_text(self):
+ text = u"abcüöä"
+ self._test_write_file(text, text.encode('utf8'))
+
+ def test_write_file_dedent(self):
+ text = u"""
+ A horse is a horse,
+ of course, of course,
+ And no one can talk to a horse
+ of course
+ """
+ self._test_write_file(text, textwrap.dedent(text).encode('utf8'), dedent=True)
+
+ def test_write_file_bytes(self):
+ self._test_write_file(b"ab\0c", b"ab\0c")
+
+ def test_write_newer_file(self):
+ file_path_1 = self._test_path("abcfile1.txt")
+ file_path_2 = self._test_path("abcfile2.txt")
+ write_file(file_path_1, "abc")
+ assert os.path.isfile(file_path_1)
+ write_newer_file(file_path_2, file_path_1, "xyz")
+ assert os.path.isfile(file_path_2)
+ assert os.path.getmtime(file_path_2) > os.path.getmtime(file_path_1)
+
+ def test_write_newer_file_same(self):
+ file_path = self._test_path("abcfile.txt")
+ write_file(file_path, "abc")
+ mtime = os.path.getmtime(file_path)
+ write_newer_file(file_path, file_path, "xyz")
+ assert os.path.getmtime(file_path) > mtime
+
+ def test_write_newer_file_fresh(self):
+ file_path = self._test_path("abcfile.txt")
+ assert not os.path.exists(file_path)
+ write_newer_file(file_path, file_path, "xyz")
+ assert os.path.isfile(file_path)
+
+ def test_parse_pattern(self):
+ self.assertEqual(
+ _parse_pattern("pattern"),
+ (None, None, 'pattern')
+ )
+ self.assertEqual(
+ _parse_pattern("/start/:pattern"),
+ ('start', None, 'pattern')
+ )
+ self.assertEqual(
+ _parse_pattern(":/end/ pattern"),
+ (None, 'end', 'pattern')
+ )
+ self.assertEqual(
+ _parse_pattern("/start/:/end/ pattern"),
+ ('start', 'end', 'pattern')
+ )
+ self.assertEqual(
+ _parse_pattern("/start/:/end/pattern"),
+ ('start', 'end', 'pattern')
+ )