File: pytest9.patch

package info (click to toggle)
barectf 3.1.2-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,840 kB
  • sloc: python: 3,781; ansic: 1,585; makefile: 45; sh: 11
file content (178 lines) | stat: -rw-r--r-- 6,185 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
Port tests to pytest9.

--- a/tests/config/yaml/conftest.py
+++ b/tests/config/yaml/conftest.py
@@ -22,18 +22,17 @@
 # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
 import pytest
-import os.path
 import barectf
 
 
-def pytest_collect_file(parent, path):
+def pytest_collect_file(parent, file_path):
     yaml_ext = '.yaml'
 
-    if path.ext != yaml_ext:
+    if file_path.suffix != yaml_ext:
         # not a YAML file: cancel
         return
 
-    if path.fnmatch('*.inc.yaml'):
+    if file_path.match('*.inc.yaml'):
         # not a top-level test file (partial inclusion YAML file)
         return
 
@@ -44,26 +43,26 @@
     # * `pct-no.yaml`
     # * `stream`
     # * `fail`
-    path_str = str(path)
+    elem_path = file_path
     elems = []
 
     while True:
-        elem = os.path.basename(path_str)
+        elem = elem_path.name
 
         if elem == 'configs':
             break
 
         elems.append(elem)
-        path_str = os.path.dirname(path_str)
+        elem_path = elem_path.parent
 
     # create a unique test name
     name = f'test-{"-".join(reversed(elems))}'.replace(yaml_ext, '')
 
     # create the file node
     if 'fail' in elems:
-        return _YamlFileFail.from_parent(parent, fspath=path, name=name)
+        return _YamlFileFail.from_parent(parent, path=file_path, name=name)
     elif 'pass' in elems:
-        return _YamlFilePass.from_parent(parent, fspath=path, name=name)
+        return _YamlFilePass.from_parent(parent, path=file_path, name=name)
     else:
         # YAML file is not a test case
         return
@@ -98,8 +97,8 @@
 
 
 class _YamlFile(pytest.File):
-    def __init__(self, parent, fspath, name):
-        super().__init__(parent=parent, fspath=fspath)
+    def __init__(self, *, name, **kwargs):
+        super().__init__(**kwargs)
         self._name = name
 
     def collect(self):
--- a/tests/tracing/conftest.py
+++ b/tests/tracing/conftest.py
@@ -30,10 +30,10 @@
 import tempfile
 
 
-def pytest_collect_file(parent, path):
+def pytest_collect_file(parent, file_path):
     yaml_ext = '.yaml'
 
-    if path.ext != yaml_ext:
+    if file_path.suffix != yaml_ext:
         # not a YAML file: cancel
         return
 
@@ -49,35 +49,32 @@
     #
     # `file_name`:
     #     `of-str.yaml`
-    path_str = str(path)
-    file_name = os.path.basename(path_str)
-    subcat_dir = os.path.dirname(path_str)
-    subcat = os.path.basename(subcat_dir)
-    cat_dir = os.path.dirname(subcat_dir)
-    cat = os.path.basename(cat_dir)
-    configs_dir = os.path.dirname(cat_dir)
+    file_name = file_path.name
+    subcat_dir = file_path.parent
+    subcat = subcat_dir.name
+    cat_dir = subcat_dir.parent
+    cat = cat_dir.name
+    configs_dir = cat_dir.parent
     valid_cats = {
         'basic',
         'counter-clock',
         'basic-extra-pc-ft-members',
     }
 
-    if cat not in valid_cats or os.path.basename(configs_dir) != 'configs':
+    if cat not in valid_cats or configs_dir.name != 'configs':
         # not a YAML configuration test
         return
 
     # create C source, expectation file, and support directory paths
-    base_dir = os.path.dirname(configs_dir)
+    base_dir = configs_dir.parent
     base_name = file_name.replace(yaml_ext, '')
-    subcat_rel_dir = os.path.join(cat, subcat)
-    src_path = os.path.join(base_dir, 'src', subcat_rel_dir, f'{base_name}.c')
-    data_expect_path = os.path.join(base_dir, 'expect', subcat_rel_dir, f'{base_name}.data.expect')
-    metadata_expect_path = os.path.join(base_dir, 'expect', subcat_rel_dir,
-                                        f'{base_name}.metadata.expect')
-    support_dir_path = os.path.join(base_dir, 'support', cat)
+    src_path = base_dir.joinpath('src', cat, subcat, base_name).with_suffix('.c')
+    data_expect_path = base_dir.joinpath('expect', cat, subcat, base_name).with_suffix('.data.expect')
+    metadata_expect_path = base_dir.joinpath('expect', cat, subcat, base_name).with_suffix('.metadata.expect')
+    support_dir_path = base_dir.joinpath('support', cat)
 
     # create the file node
-    return _YamlFile.from_parent(parent, fspath=path, src_path=src_path,
+    return _YamlFile.from_parent(parent, path=file_path, src_path=src_path,
                                  data_expect_path=data_expect_path,
                                  metadata_expect_path=metadata_expect_path,
                                  support_dir_path=support_dir_path,
@@ -85,9 +82,9 @@
 
 
 class _YamlFile(pytest.File):
-    def __init__(self, parent, fspath, src_path, data_expect_path, metadata_expect_path,
-                 support_dir_path, name):
-        super().__init__(parent=parent, fspath=fspath)
+    def __init__(self, *, src_path, data_expect_path, metadata_expect_path,
+                 support_dir_path, name, **kwargs):
+        super().__init__(**kwargs)
         self._name = name
         self._src_path = src_path
         self._data_expect_path = data_expect_path
@@ -103,9 +100,9 @@
 
 
 class _YamlItem(pytest.Item):
-    def __init__(self, parent, name, src_path, data_expect_path, metadata_expect_path,
-                 support_dir_path):
-        super().__init__(parent=parent, name=name)
+    def __init__(self, *, src_path, data_expect_path, metadata_expect_path,
+                 support_dir_path, **kwargs):
+        super().__init__(**kwargs)
         self._src_path = src_path
         self._data_expect_path = data_expect_path
         self._metadata_expect_path = metadata_expect_path
@@ -116,7 +113,7 @@
         tmpdir = tempfile.TemporaryDirectory(prefix='pytest-barectf')
 
         # create barectf configuration
-        with open(self.fspath) as f:
+        with open(self.path) as f:
             cfg = barectf.configuration_from_file(f, inclusion_directories=[self._support_dir_path])
 
         # generate and write C code files
@@ -193,7 +190,7 @@
         tmpdir.cleanup()
 
     def repr_failure(self, excinfo, style=None):
-        return f'`{self.fspath}` failed: {excinfo}.'
+        return f'`{self.path}` failed: {excinfo}.'
 
     def reportinfo(self):
-        return self.fspath, None, self.name
+        return self.path, None, self.name