File: Fixed-tmpdir-race-condition-in-dotexport-test.patch

package info (click to toggle)
anytree 2.12.1-3.1
  • links: PTS
  • area: main
  • in suites: forky, sid, trixie
  • size: 872 kB
  • sloc: python: 4,044; makefile: 12
file content (77 lines) | stat: -rw-r--r-- 2,502 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
Description: Change dotexport test to use tmpdir to fix race condition
 In the upstream package, the dotexport test manually creates and
 deletes temporary directories in a way that exposes it to possible
 race conditions. This patch corrects that by having it use the pytest
 tmpdir constructs, which handle temporary directories safely.
Author: Mitchell Augustin <mitchell@mitchellaugustin.com>
Forwarded: https://github.com/c0fec0de/anytree/pull/261

---
Origin: other, https://github.com/c0fec0de/anytree/pull/261/commits/48d366741cf18f21c0190ad2b130dea97b2d7ff6
Bug: https://github.com/c0fec0de/anytree/issues/258
Last-Update: 2024-06-13

--- anytree-2.12.1.orig/tests/test_dotexport.py
+++ anytree-2.12.1/tests/test_dotexport.py
@@ -9,22 +9,9 @@ from anytree.dotexport import RenderTree
 from .helper import with_setup
 
 TESTPATH = dirname(__file__)
-GENPATH = join(TESTPATH, "dotexport")
 REFPATH = join(TESTPATH, "refdata")
 
-
-def setup():
-    if not exists(GENPATH):
-        makedirs(GENPATH)
-
-
-def teardown():
-    if exists(GENPATH):
-        rmtree(GENPATH)
-
-
-@with_setup(setup, teardown)
-def test_tree1():
+def test_tree1(tmpdir):
     """Tree1."""
     root = Node("root")
     s0 = Node("sub0", parent=root)
@@ -36,12 +23,11 @@ def test_tree1():
     s1c = Node("sub1C", parent=s1)
     Node(99, parent=s1c)
 
-    RenderTreeGraph(root).to_dotfile(join(GENPATH, "tree1.dot"))
-    assert cmp(join(GENPATH, "tree1.dot"), join(REFPATH, "tree1.dot"))
+    RenderTreeGraph(root).to_dotfile(join(tmpdir, "tree1.dot"))
+    assert cmp(join(tmpdir, "tree1.dot"), join(REFPATH, "tree1.dot"))
 
 
-@with_setup(setup, teardown)
-def test_tree2():
+def test_tree2(tmpdir):
     """Tree2."""
     root = Node("root")
     s0 = Node("sub0", parent=root, edge=2)
@@ -67,12 +53,11 @@ def test_tree2():
         edgeattrfunc=edgeattrfunc,
     )
 
-    r.to_dotfile(join(GENPATH, "tree2.dot"))
-    assert cmp(join(GENPATH, "tree2.dot"), join(REFPATH, "tree2.dot"))
+    r.to_dotfile(join(tmpdir, "tree2.dot"))
+    assert cmp(join(tmpdir, "tree2.dot"), join(REFPATH, "tree2.dot"))
 
 
-@with_setup(setup, teardown)
-def test_tree_png():
+def test_tree_png(tmpdir):
     """Tree to png."""
     root = Node("root")
     s0 = Node("sub0", parent=root)
@@ -84,4 +69,4 @@ def test_tree_png():
     s1c = Node("sub1C", parent=s1)
     Node("sub1Ca", parent=s1c)
 
-    RenderTreeGraph(root).to_picture(join(GENPATH, "tree1.png"))
+    RenderTreeGraph(root).to_picture(join(tmpdir, "tree1.png"))