File tree Expand file tree Collapse file tree 3 files changed +12
-39
lines changed
Expand file tree Collapse file tree 3 files changed +12
-39
lines changed Original file line number Diff line number Diff line change @@ -48,33 +48,3 @@ def twenty_cls_tests():
4848 for i in range (20 ):
4949 code .append ("\t def test_b{0}(self): self.assertTrue\n " .format (str (i ).zfill (2 )))
5050 return "" .join (code )
51-
52-
53- def _deindent_source (source ):
54- """
55- A minimal replacement for py.code.Source to deindent inlined test code.
56- Looks for the first non-empty line to determine deindent offset, doesn't
57- attempt to understand the code, line continuations, etc.
58- """
59- lines = source .splitlines ()
60- for line in lines :
61- stripped = line .lstrip ()
62- if stripped :
63- offset = len (line ) - len (stripped )
64- break
65- else :
66- offset = 0
67-
68- output_lines = []
69- for line in lines :
70- output_lines .append (line [offset :])
71-
72- return "\n " .join (output_lines )
73-
74-
75- @pytest .fixture
76- def deindent_source ():
77- """
78- Returns a helper function to deindent inlined source code.
79- """
80- return _deindent_source
Original file line number Diff line number Diff line change 11# -*- coding: utf-8 -*-
22import collections
33import re
4+ import textwrap
45
56import pytest
67
78
89@pytest .fixture
9- def tmp_tree_of_tests (testdir , deindent_source ):
10+ def tmp_tree_of_tests (testdir ):
1011 """
1112 Creates a directory structure:
1213 tmpdir/
@@ -24,7 +25,7 @@ def tmp_tree_of_tests(testdir, deindent_source):
2425 sup = testdir .mkpydir ("shallow_tests" )
2526
2627 sup .join ("test_a.py" ).write (
27- deindent_source ("""
28+ textwrap . dedent ("""
2829 def test_a1():
2930 assert False
3031 def test_a2():
@@ -35,7 +36,7 @@ def test_a3():
3536 )
3637
3738 sup .join ("test_ax.py" ).write (
38- deindent_source ("""
39+ textwrap . dedent ("""
3940 def test_ax1():
4041 assert True
4142 def test_ax2():
@@ -48,7 +49,7 @@ def test_ax3():
4849 sub = testdir .mkpydir ("shallow_tests/deep_tests" )
4950
5051 sub .join ("test_b.py" ).write (
51- deindent_source ("""
52+ textwrap . dedent ("""
5253 def test_b1():
5354 assert True
5455 def test_b2():
@@ -59,14 +60,14 @@ def test_b3():
5960 )
6061
6162 sub .join ("test_c.py" ).write (
62- deindent_source ("""
63+ textwrap . dedent ("""
6364 def test_c1():
6465 assert True
6566 """ )
6667 )
6768
6869 sub .join ("test_d.py" ).write (
69- deindent_source ("""
70+ textwrap . dedent ("""
7071 def test_d1():
7172 assert True
7273 def test_d2():
@@ -75,7 +76,7 @@ def test_d2():
7576 )
7677
7778 sub .join ("test_e.py" ).write (
78- deindent_source ("""
79+ textwrap . dedent ("""
7980 from unittest import TestCase
8081 class EeTest(TestCase):
8182 def test_ee1(self):
Original file line number Diff line number Diff line change 11# -*- coding: utf-8 -*-
2+ import textwrap
3+
24import pytest
35
46
57@pytest .fixture
6- def tmp_tree_of_tests (testdir , deindent_source ):
8+ def tmp_tree_of_tests (testdir ):
79 """
810 Creates a directory structure:
911 tmpdir/
@@ -15,7 +17,7 @@ def tmp_tree_of_tests(testdir, deindent_source):
1517 utils_package .join ("__init__.py" ).write ("" )
1618
1719 utils_package .join ("foo.py" ).write (
18- deindent_source ('''
20+ textwrap . dedent ('''
1921 def add(a, b):
2022 """
2123 >>> add(1, 1)
You can’t perform that action at this time.
0 commit comments