Debian Codegraph @

debian/patches/test-support-running-tests-out-of-tree.patch

raw
1 From: Benjamin Drung <[email protected]>
2 Date: Thu, 7 Dec 2023 13:16:10 +0100
3 Subject: test: support running tests out of tree
4
5 The test `test_check_diff` will fail when running the tests out of tree,
6 because pycodestyle will fail to find `testing/data/E11.py`.
7
8 So derive the relative path to the patched file from the `test_shell.py`
9 location.
10
11 Forwarded: https://github.com/PyCQA/pycodestyle/pull/1220
12 Signed-off-by: Benjamin Drung <[email protected]>
13 ---
14 tests/test_shell.py | 21 ++++++++++++---------
15 1 file changed, 12 insertions(+), 9 deletions(-)
16
17 diff --git a/tests/test_shell.py b/tests/test_shell.py
18 index e4a75e1..00ec31f 100644
19 --- a/tests/test_shell.py
20 +++ b/tests/test_shell.py
21 @@ -1,6 +1,7 @@
22 import configparser
23 import io
24 import os.path
25 +import pathlib
26 import sys
27 import unittest
28
29 @@ -127,9 +128,11 @@ class ShellTestCase(unittest.TestCase):
30
31 def test_check_diff(self):
32 pycodestyle.PROJECT_CONFIG = ()
33 + topdir = pathlib.Path(__file__).parent.parent
34 + test_file = os.path.relpath(topdir / "testing" / "data" / "E11.py")
35 diff_lines = [
36 - "--- testing/data/E11.py 2006-06-01 08:49:50 +0500",
37 - "+++ testing/data/E11.py 2008-04-06 17:36:29 +0500",
38 + f"--- {test_file} 2006-06-01 08:49:50 +0500",
39 + f"+++ {test_file} 2008-04-06 17:36:29 +0500",
40 "@@ -2,4 +2,7 @@",
41 " if x > 2:",
42 " print x",
43 @@ -153,8 +156,8 @@ class ShellTestCase(unittest.TestCase):
44 self.assertTrue(msg.startswith(' E11'))
45
46 diff_lines[:2] = [
47 - "--- a/testing/data/E11.py 2006-06-01 08:49 +0400",
48 - "+++ b/testing/data/E11.py 2008-04-06 17:36 +0400",
49 + f"--- a/{test_file} 2006-06-01 08:49 +0400",
50 + f"+++ b/{test_file} 2008-04-06 17:36 +0400",
51 ]
52 self.stdin = '\n'.join(diff_lines)
53 stdout, stderr, errcode = self.pycodestyle('--diff')
54 @@ -169,10 +172,10 @@ class ShellTestCase(unittest.TestCase):
55
56 # issue #127, #137: one-line chunks
57 diff_lines[:-1] = [
58 - "diff --git a/testing/data/E11.py b/testing/data/E11.py",
59 + f"diff --git a/{test_file} b/{test_file}",
60 "index 8735e25..2ecb529 100644",
61 - "--- a/testing/data/E11.py",
62 - "+++ b/testing/data/E11.py",
63 + f"--- a/{test_file}",
64 + f"+++ b/{test_file}",
65 "@@ -5,0 +6 @@ if True:",
66 "+ print",
67 ]
68 @@ -181,8 +184,8 @@ class ShellTestCase(unittest.TestCase):
69 stdout = stdout.splitlines()
70 self.assertEqual(errcode, 1)
71 self.assertFalse(stderr)
72 - self.assertTrue('testing/data/E11.py:6:6: E111 ' in stdout[0])
73 - self.assertTrue('testing/data/E11.py:6:6: E117 ' in stdout[1])
74 + self.assertTrue(f'{test_file}:6:6: E111 ' in stdout[0])
75 + self.assertTrue(f'{test_file}:6:6: E117 ' in stdout[1])
76
77 # missing '--diff'
78 self.stdin = '\n'.join(diff_lines)