Skip to content

Commit fe9dee8

Browse files
Use pytest in-built fixture for tmpdir
1 parent b3d649f commit fe9dee8

7 files changed

Lines changed: 98 additions & 98 deletions

File tree

docs/source/conf.py

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,16 @@
1919
#
2020
import os
2121
import sys
22+
2223
# So autodoc can import our package
23-
sys.path.insert(0, os.path.abspath('../..'))
24+
sys.path.insert(0, os.path.abspath("../.."))
2425

2526
# Warn about all references to unknown targets
2627
nitpicky = True
2728
# Except for these ones, which we expect to point to unknown targets:
2829
nitpick_ignore = [
2930
# Format is ("sphinx reference type", "string"), e.g.:
30-
("py:obj", "bytes-like"),
31+
("py:obj", "bytes-like")
3132
]
3233

3334
# -- General configuration ------------------------------------------------
@@ -40,16 +41,16 @@
4041
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
4142
# ones.
4243
extensions = [
43-
'sphinx.ext.autodoc',
44-
'sphinx.ext.intersphinx',
45-
'sphinx.ext.coverage',
46-
'sphinx.ext.napoleon',
47-
'sphinxcontrib_trio',
44+
"sphinx.ext.autodoc",
45+
"sphinx.ext.intersphinx",
46+
"sphinx.ext.coverage",
47+
"sphinx.ext.napoleon",
48+
"sphinxcontrib_trio",
4849
]
4950

5051
intersphinx_mapping = {
51-
"python": ('https://docs.python.org/3', None),
52-
"trio": ('https://trio.readthedocs.io/en/stable', None),
52+
"python": ("https://docs.python.org/3", None),
53+
"trio": ("https://trio.readthedocs.io/en/stable", None),
5354
}
5455

5556
autodoc_member_order = "bysource"
@@ -61,22 +62,23 @@
6162
# You can specify multiple suffix as a list of string:
6263
#
6364
# source_suffix = ['.rst', '.md']
64-
source_suffix = '.rst'
65+
source_suffix = ".rst"
6566

6667
# The master toctree document.
67-
master_doc = 'index'
68+
master_doc = "index"
6869

6970
# General information about the project.
70-
project = 'unasync'
71-
copyright = 'The unasync authors'
72-
author = 'The unasync authors'
71+
project = "unasync"
72+
copyright = "The unasync authors"
73+
author = "The unasync authors"
7374

7475
# The version info for the project you're documenting, acts as replacement for
7576
# |version| and |release|, also used in various other places throughout the
7677
# built documents.
7778
#
7879
# The short X.Y version.
7980
import unasync
81+
8082
version = unasync.__version__
8183
# The full version, including alpha/beta/rc tags.
8284
release = version
@@ -94,10 +96,10 @@
9496
exclude_patterns = []
9597

9698
# The name of the Pygments (syntax highlighting) style to use.
97-
pygments_style = 'sphinx'
99+
pygments_style = "sphinx"
98100

99101
# The default language for :: blocks
100-
highlight_language = 'python3'
102+
highlight_language = "python3"
101103

102104
# If true, `todo` and `todoList` produce output, else they produce nothing.
103105
todo_include_todos = False
@@ -108,13 +110,14 @@
108110
# The theme to use for HTML and HTML Help pages. See the documentation for
109111
# a list of builtin themes.
110112
#
111-
#html_theme = 'alabaster'
113+
# html_theme = 'alabaster'
112114

113115
# We have to set this ourselves, not only because it's useful for local
114116
# testing, but also because if we don't then RTD will throw away our
115117
# html_theme_options.
116118
import sphinx_rtd_theme
117-
html_theme = 'sphinx_rtd_theme'
119+
120+
html_theme = "sphinx_rtd_theme"
118121
html_theme_path = [sphinx_rtd_theme.get_html_theme_path()]
119122

120123
# Theme options are theme-specific and customize the look and feel of a theme
@@ -134,13 +137,13 @@
134137
# Add any paths that contain custom static files (such as style sheets) here,
135138
# relative to this directory. They are copied after the builtin static files,
136139
# so a file named "default.css" will overwrite the builtin "default.css".
137-
html_static_path = ['_static']
140+
html_static_path = ["_static"]
138141

139142

140143
# -- Options for HTMLHelp output ------------------------------------------
141144

142145
# Output file base name for HTML help builder.
143-
htmlhelp_basename = 'unasyncdoc'
146+
htmlhelp_basename = "unasyncdoc"
144147

145148

146149
# -- Options for LaTeX output ---------------------------------------------
@@ -149,15 +152,12 @@
149152
# The paper size ('letterpaper' or 'a4paper').
150153
#
151154
# 'papersize': 'letterpaper',
152-
153155
# The font size ('10pt', '11pt' or '12pt').
154156
#
155157
# 'pointsize': '10pt',
156-
157158
# Additional stuff for the LaTeX preamble.
158159
#
159160
# 'preamble': '',
160-
161161
# Latex figure (float) alignment
162162
#
163163
# 'figure_align': 'htbp',
@@ -166,20 +166,14 @@
166166
# Grouping the document tree into LaTeX files. List of tuples
167167
# (source start file, target name, title,
168168
# author, documentclass [howto, manual, or own class]).
169-
latex_documents = [
170-
(master_doc, 'unasync.tex', 'Trio Documentation',
171-
author, 'manual'),
172-
]
169+
latex_documents = [(master_doc, "unasync.tex", "Trio Documentation", author, "manual")]
173170

174171

175172
# -- Options for manual page output ---------------------------------------
176173

177174
# One entry per manual page. List of tuples
178175
# (source start file, name, description, authors, manual section).
179-
man_pages = [
180-
(master_doc, 'unasync', 'unasync Documentation',
181-
[author], 1)
182-
]
176+
man_pages = [(master_doc, "unasync", "unasync Documentation", [author], 1)]
183177

184178

185179
# -- Options for Texinfo output -------------------------------------------
@@ -188,7 +182,13 @@
188182
# (source start file, target name, title, author,
189183
# dir menu entry, description, category)
190184
texinfo_documents = [
191-
(master_doc, 'unasync', 'unasync Documentation',
192-
author, 'unasync', 'The async transformation code.',
193-
'Miscellaneous'),
185+
(
186+
master_doc,
187+
"unasync",
188+
"unasync Documentation",
189+
author,
190+
"unasync",
191+
"The async transformation code.",
192+
"Miscellaneous",
193+
)
194194
]

setup.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,14 @@
2929
"Operating System :: POSIX :: Linux",
3030
"Operating System :: MacOS :: MacOS X",
3131
"Operating System :: Microsoft :: Windows",
32-
'Programming Language :: Python :: 2',
33-
'Programming Language :: Python :: 2.7',
34-
'Programming Language :: Python :: 3',
35-
'Programming Language :: Python :: 3.4',
36-
'Programming Language :: Python :: 3.5',
37-
'Programming Language :: Python :: 3.6',
38-
'Programming Language :: Python :: 3.7',
39-
'Programming Language :: Python :: 3.8',
32+
"Programming Language :: Python :: 2",
33+
"Programming Language :: Python :: 2.7",
34+
"Programming Language :: Python :: 3",
35+
"Programming Language :: Python :: 3.4",
36+
"Programming Language :: Python :: 3.5",
37+
"Programming Language :: Python :: 3.6",
38+
"Programming Language :: Python :: 3.7",
39+
"Programming Language :: Python :: 3.8",
4040
"Programming Language :: Python :: Implementation :: CPython",
4141
"Programming Language :: Python :: Implementation :: PyPy",
4242
],

src/unasync/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ def unasync_file(filepath, fromdir, todir):
9393
write_kwargs = {}
9494
if sys.version_info[0] >= 3:
9595
encoding, _ = std_tokenize.detect_encoding(f.readline)
96-
write_kwargs['encoding'] = encoding
96+
write_kwargs["encoding"] = encoding
9797
f.seek(0)
9898
tokens = tokenize(f)
9999
tokens = unasync_tokens(tokens)

test-requirements.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
pytest-cov
2-
backports.tempfile
1+
pytest-cov

tests/async/simple.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,12 @@ def __init__(self, a, b):
55
self.s = "UTF-8: ❄"
66

77
async def get_a_b(self):
8-
s = "a is %s b is %s" % \
9-
(self.a,
10-
self.b)
8+
s = "a is %s b is %s" % (self.a, self.b)
119
return s
1210

1311
async def f(self):
1412
return await 1
1513

14+
1615
async def f():
1716
return await 1

tests/sync/simple.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,12 @@ def __init__(self, a, b):
55
self.s = "UTF-8: ❄"
66

77
def get_a_b(self):
8-
s = "a is %s b is %s" % \
9-
(self.a,
10-
self.b)
8+
s = "a is %s b is %s" % (self.a, self.b)
119
return s
1210

1311
def f(self):
1412
return 1
1513

14+
1615
def f():
1716
return 1

tests/test_unasync.py

Lines changed: 50 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@
66

77
import pytest
88

9-
# Needed to get tempfile.TemporaryDirectory in Python 2
10-
from backports import tempfile
11-
129
import unasync
1310

1411
TEST_DIR = os.path.dirname(os.path.abspath(__file__))
@@ -32,47 +29,53 @@ def list_files(startpath):
3229

3330

3431
@pytest.mark.parametrize("source_file", TEST_FILES)
35-
def test_unasync(source_file):
36-
with tempfile.TemporaryDirectory() as tmpdir:
37-
unasync.unasync_file(
38-
os.path.join(ASYNC_DIR, source_file), fromdir=ASYNC_DIR, todir=tmpdir
39-
)
40-
41-
encoding = "latin-1" if "encoding" in source_file else "utf-8"
42-
with io.open(os.path.join(SYNC_DIR, source_file), encoding=encoding) as f:
43-
truth = f.read()
44-
with io.open(os.path.join(tmpdir, source_file), encoding=encoding) as f:
45-
unasynced_code = f.read()
46-
assert unasynced_code == truth
47-
48-
49-
def test_build_py():
50-
with tempfile.TemporaryDirectory() as tmpdir:
51-
source_pkg_dir = os.path.join(TEST_DIR, "example_pkg")
52-
pkg_dir = os.path.join(tmpdir, "example_pkg")
53-
shutil.copytree(source_pkg_dir, pkg_dir)
54-
55-
env = copy.copy(os.environ)
56-
env["PYTHONPATH"] = os.path.realpath(os.path.join(TEST_DIR, ".."))
57-
subprocess.check_call(["python", "setup.py", "build"], cwd=pkg_dir, env=env)
58-
59-
unasynced = os.path.join(pkg_dir, "build/lib/example_pkg/_sync/__init__.py")
60-
with open(unasynced) as f:
61-
unasynced_code = f.read()
62-
assert unasynced_code == "def f():\n return 1\n"
63-
64-
65-
def test_project_structure_after_build_py():
66-
with tempfile.TemporaryDirectory() as tmpdir:
67-
source_pkg_dir = os.path.join(TEST_DIR, "example_pkg")
68-
pkg_dir = os.path.join(tmpdir, "example_pkg")
69-
shutil.copytree(source_pkg_dir, pkg_dir)
70-
71-
env = copy.copy(os.environ)
72-
env["PYTHONPATH"] = os.path.realpath(os.path.join(TEST_DIR, ".."))
73-
subprocess.check_call(["python", "setup.py", "build"], cwd=pkg_dir, env=env)
74-
75-
_async_dir_tree = list_files(os.path.join(source_pkg_dir, "src/example_pkg/_async/."))
76-
unasynced_dir_tree = list_files(os.path.join(pkg_dir, "build/lib/example_pkg/_sync/."))
77-
78-
assert _async_dir_tree == unasynced_dir_tree
32+
def test_unasync(tmpdir, source_file):
33+
34+
tmpdir = str(tmpdir)
35+
36+
unasync.unasync_file(
37+
os.path.join(ASYNC_DIR, source_file), fromdir=ASYNC_DIR, todir=tmpdir
38+
)
39+
40+
encoding = "latin-1" if "encoding" in source_file else "utf-8"
41+
with io.open(os.path.join(SYNC_DIR, source_file), encoding=encoding) as f:
42+
truth = f.read()
43+
with io.open(os.path.join(tmpdir, source_file), encoding=encoding) as f:
44+
unasynced_code = f.read()
45+
assert unasynced_code == truth
46+
47+
48+
def test_build_py(tmpdir):
49+
50+
source_pkg_dir = os.path.join(TEST_DIR, "example_pkg")
51+
pkg_dir = os.path.join(tmpdir, "example_pkg")
52+
shutil.copytree(source_pkg_dir, pkg_dir)
53+
54+
env = copy.copy(os.environ)
55+
env["PYTHONPATH"] = os.path.realpath(os.path.join(TEST_DIR, ".."))
56+
subprocess.check_call(["python", "setup.py", "build"], cwd=pkg_dir, env=env)
57+
58+
unasynced = os.path.join(pkg_dir, "build/lib/example_pkg/_sync/__init__.py")
59+
with open(unasynced) as f:
60+
unasynced_code = f.read()
61+
assert unasynced_code == "def f():\n return 1\n"
62+
63+
64+
def test_project_structure_after_build_py(tmpdir):
65+
66+
source_pkg_dir = os.path.join(TEST_DIR, "example_pkg")
67+
pkg_dir = os.path.join(tmpdir, "example_pkg")
68+
shutil.copytree(source_pkg_dir, pkg_dir)
69+
70+
env = copy.copy(os.environ)
71+
env["PYTHONPATH"] = os.path.realpath(os.path.join(TEST_DIR, ".."))
72+
subprocess.check_call(["python", "setup.py", "build"], cwd=pkg_dir, env=env)
73+
74+
_async_dir_tree = list_files(
75+
os.path.join(source_pkg_dir, "src/example_pkg/_async/.")
76+
)
77+
unasynced_dir_tree = list_files(
78+
os.path.join(pkg_dir, "build/lib/example_pkg/_sync/.")
79+
)
80+
81+
assert _async_dir_tree == unasynced_dir_tree

0 commit comments

Comments
 (0)