Skip to content

Commit 9f45efe

Browse files
committed
Format
1 parent a9b0571 commit 9f45efe

File tree

11 files changed

+147
-115
lines changed

11 files changed

+147
-115
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
hypothesis>=3.55
22
pytest>=3.5.0
33
setuptools-rust>=0.10.2
4+
black

examples/rustapi_module/setup.py

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ def run(self):
1212
self.run_command("test_rust")
1313

1414
import subprocess
15-
errno = subprocess.call(['pytest', 'tests'])
15+
16+
errno = subprocess.call(["pytest", "tests"])
1617
raise SystemExit(errno)
1718

1819

@@ -21,41 +22,48 @@ def get_py_version_cfgs():
2122
version = sys.version_info[0:2]
2223

2324
if version[0] == 2:
24-
return ['--cfg=Py_2']
25+
return ["--cfg=Py_2"]
2526

2627
py3_min = 5
2728
out_cfg = []
2829
for minor in range(py3_min, version[1] + 1):
29-
out_cfg.append('--cfg=Py_3_%d' % minor)
30+
out_cfg.append("--cfg=Py_3_%d" % minor)
3031

3132
return out_cfg
3233

3334

3435
install_requires = []
35-
tests_require = install_requires + ['pytest', 'pytest-benchmark']
36+
tests_require = install_requires + ["pytest", "pytest-benchmark"]
3637

3738
setup(
38-
name='rustapi-module',
39-
version='0.1.0',
39+
name="rustapi-module",
40+
version="0.1.0",
4041
classifiers=[
41-
'License :: OSI Approved :: MIT License',
42-
'Development Status :: 3 - Alpha',
43-
'Intended Audience :: Developers',
44-
'Programming Language :: Python',
45-
'Programming Language :: Rust',
46-
'Operating System :: POSIX',
47-
'Operating System :: MacOS :: MacOS X',
42+
"License :: OSI Approved :: MIT License",
43+
"Development Status :: 3 - Alpha",
44+
"Intended Audience :: Developers",
45+
"Programming Language :: Python",
46+
"Programming Language :: Rust",
47+
"Operating System :: POSIX",
48+
"Operating System :: MacOS :: MacOS X",
49+
],
50+
packages=["rustapi_module"],
51+
rust_extensions=[
52+
RustExtension(
53+
"rustapi_module.othermod", "Cargo.toml", rustc_flags=get_py_version_cfgs()
54+
),
55+
RustExtension(
56+
"rustapi_module.datetime", "Cargo.toml", rustc_flags=get_py_version_cfgs()
57+
),
58+
RustExtension(
59+
"rustapi_module.subclassing",
60+
"Cargo.toml",
61+
rustc_flags=get_py_version_cfgs(),
62+
),
4863
],
49-
packages=['rustapi_module'],
50-
rust_extensions=[RustExtension('rustapi_module.othermod', 'Cargo.toml',
51-
rustc_flags=get_py_version_cfgs()),
52-
RustExtension('rustapi_module.datetime', 'Cargo.toml',
53-
rustc_flags=get_py_version_cfgs()),
54-
RustExtension('rustapi_module.subclassing', 'Cargo.toml',
55-
rustc_flags=get_py_version_cfgs())],
5664
install_requires=install_requires,
5765
tests_require=tests_require,
5866
include_package_data=True,
5967
zip_safe=False,
60-
cmdclass=dict(test=PyTest)
68+
cmdclass=dict(test=PyTest),
6169
)

examples/rustapi_module/src/datetime.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use pyo3::prelude::*;
22
use pyo3::types::{
3-
PyDate, PyDateAccess, PyDateTime, PyDelta, PyDeltaAccess, PyTime, PyTimeAccess,
4-
PyTuple, PyTzInfo,
3+
PyDate, PyDateAccess, PyDateTime, PyDelta, PyDeltaAccess, PyTime, PyTimeAccess, PyTuple,
4+
PyTzInfo,
55
};
66

77
#[pyfunction]

examples/rustapi_module/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ extern crate pyo3;
66
use pyo3::prelude::*;
77
use subclassing::Subclassable;
88

9+
pub mod datetime;
910
pub mod othermod;
1011
pub mod subclassing;
11-
pub mod datetime;

examples/rustapi_module/src/subclassing.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,3 @@ fn subclassing(_py: Python, m: &PyModule) -> PyResult<()> {
1818
m.add_class::<Subclassable>()?;
1919
Ok(())
2020
}
21-

examples/rustapi_module/tests/test_datetime.py

Lines changed: 87 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
1-
import rustapi_module.datetime as rdt
2-
3-
import sys
41
import datetime as pdt
2+
import sys
53

6-
import pytest
4+
import pytest
5+
import rustapi_module.datetime as rdt
76
from hypothesis import given
87
from hypothesis import strategies as st
98
from hypothesis.strategies import dates, datetimes
109

10+
1111
# Constants
1212
def _get_utc():
13-
timezone = getattr(pdt, 'timezone', None)
13+
timezone = getattr(pdt, "timezone", None)
1414
if timezone:
1515
return timezone.utc
1616
else:
17+
1718
class UTC(pdt.tzinfo):
1819
def utcoffset(self, dt):
1920
return pdt.timedelta(0)
@@ -26,6 +27,7 @@ def tzname(self, dt):
2627

2728
return UTC()
2829

30+
2931
UTC = _get_utc()
3032

3133
MAX_SECONDS = int(pdt.timedelta.max.total_seconds())
@@ -42,19 +44,22 @@ def tzname(self, dt):
4244
MAX_MICROSECONDS = int(pdt.timedelta.max.total_seconds() * 1e6)
4345
MIN_MICROSECONDS = int(pdt.timedelta.min.total_seconds() * 1e6)
4446

45-
HAS_FOLD = getattr(pdt.datetime, 'fold', False)
46-
47+
HAS_FOLD = getattr(pdt.datetime, "fold", False)
4748

4849
# Helper functions
49-
get_timestamp = getattr(pdt.datetime, 'timestamp', None)
50+
get_timestamp = getattr(pdt.datetime, "timestamp", None)
5051
if get_timestamp is None:
52+
5153
def get_timestamp(dt):
5254
# Python 2 compatibility
5355
return (dt - pdt.datetime(1970, 1, 1)).total_seconds()
5456

5557

56-
xfail_date_bounds = pytest.mark.xfail(sys.version_info < (3, 6),
57-
reason="Date bounds were not checked in the C constructor prior to version 3.6")
58+
xfail_date_bounds = pytest.mark.xfail(
59+
sys.version_info < (3, 6),
60+
reason="Date bounds were not checked in the C constructor prior to version 3.6",
61+
)
62+
5863

5964
# Tests
6065
def test_date():
@@ -81,11 +86,14 @@ def test_date_from_timestamp(d):
8186
assert rdt.date_from_timestamp(int(ts)) == pdt.date.fromtimestamp(ts)
8287

8388

84-
@pytest.mark.parametrize('args, kwargs', [
85-
((0, 0, 0, 0, None), {}),
86-
((1, 12, 14, 124731), {}),
87-
((1, 12, 14, 124731), {'tzinfo': UTC}),
88-
])
89+
@pytest.mark.parametrize(
90+
"args, kwargs",
91+
[
92+
((0, 0, 0, 0, None), {}),
93+
((1, 12, 14, 124731), {}),
94+
((1, 12, 14, 124731), {"tzinfo": UTC}),
95+
],
96+
)
8997
def test_time(args, kwargs):
9098
act = rdt.make_time(*args, **kwargs)
9199
exp = pdt.time(*args, **kwargs)
@@ -116,55 +124,58 @@ def test_time_fold(t):
116124

117125

118126
@pytest.mark.skipif(not HAS_FOLD, reason="Feature not available before 3.6")
119-
@pytest.mark.parametrize('fold', [False, True])
127+
@pytest.mark.parametrize("fold", [False, True])
120128
def test_time_fold(fold):
121129
t = rdt.time_with_fold(0, 0, 0, 0, None, fold)
122130
assert t.fold == fold
123131

124132

125133
@pytest.mark.xfail
126-
@pytest.mark.parametrize('args', [
127-
(-1, 0, 0, 0),
128-
(0, -1, 0, 0),
129-
(0, 0, -1, 0),
130-
(0, 0, 0, -1),
131-
])
134+
@pytest.mark.parametrize(
135+
"args", [(-1, 0, 0, 0), (0, -1, 0, 0), (0, 0, -1, 0), (0, 0, 0, -1)]
136+
)
132137
def test_invalid_time_fails_xfail(args):
133138
with pytest.raises(ValueError):
134139
rdt.make_time(*args)
135140

136141

137142
@xfail_date_bounds
138-
@pytest.mark.parametrize('args', [
139-
(24, 0, 0, 0),
140-
(25, 0, 0, 0),
141-
(0, 60, 0, 0),
142-
(0, 61, 0, 0),
143-
(0, 0, 60, 0),
144-
(0, 0, 61, 0),
145-
(0, 0, 0, 1000000)
146-
])
143+
@pytest.mark.parametrize(
144+
"args",
145+
[
146+
(24, 0, 0, 0),
147+
(25, 0, 0, 0),
148+
(0, 60, 0, 0),
149+
(0, 61, 0, 0),
150+
(0, 0, 60, 0),
151+
(0, 0, 61, 0),
152+
(0, 0, 0, 1000000),
153+
],
154+
)
147155
def test_invalid_time_fails(args):
148156
with pytest.raises(ValueError):
149157
rdt.make_time(*args)
150158

151159

152-
@pytest.mark.parametrize('args', [
153-
('0', 0, 0, 0),
154-
(0, '0', 0, 0),
155-
(0, 0, '0', 0),
156-
(0, 0, 0, '0'),
157-
(0, 0, 0, 0, 'UTC')
158-
])
160+
@pytest.mark.parametrize(
161+
"args",
162+
[
163+
("0", 0, 0, 0),
164+
(0, "0", 0, 0),
165+
(0, 0, "0", 0),
166+
(0, 0, 0, "0"),
167+
(0, 0, 0, 0, "UTC"),
168+
],
169+
)
159170
def test_time_typeerror(args):
160171
with pytest.raises(TypeError):
161172
rdt.make_time(*args)
162173

163174

164-
@pytest.mark.parametrize('args, kwargs', [
165-
((2017, 9, 1, 12, 45, 30, 0), {}),
166-
((2017, 9, 1, 12, 45, 30, 0), {'tzinfo': UTC}),
167-
])
175+
@pytest.mark.parametrize(
176+
"args, kwargs",
177+
[((2017, 9, 1, 12, 45, 30, 0), {}), ((2017, 9, 1, 12, 45, 30, 0), {"tzinfo": UTC})],
178+
)
168179
def test_datetime(args, kwargs):
169180
act = rdt.make_datetime(*args, **kwargs)
170181
exp = pdt.datetime(*args, **kwargs)
@@ -176,7 +187,7 @@ def test_datetime(args, kwargs):
176187
@given(dt=st.datetimes())
177188
def test_datetime_tuple(dt):
178189
act = rdt.get_datetime_tuple(dt)
179-
exp = dt.timetuple()[0:6] + (dt.microsecond, )
190+
exp = dt.timetuple()[0:6] + (dt.microsecond,)
180191

181192
assert act == exp
182193

@@ -202,7 +213,7 @@ def test_invalid_datetime_fails():
202213

203214
def test_datetime_typeerror():
204215
with pytest.raises(TypeError):
205-
rdt.make_datetime('2011', 1, 1, 0, 0, 0, 0)
216+
rdt.make_datetime("2011", 1, 1, 0, 0, 0, 0)
206217

207218

208219
@given(dt=datetimes())
@@ -219,17 +230,20 @@ def test_datetime_from_timestamp_tzinfo():
219230
assert d1.tzinfo is d2.tzinfo
220231

221232

222-
@pytest.mark.parametrize('args', [
223-
(0, 0, 0),
224-
(1, 0, 0),
225-
(-1, 0, 0),
226-
(0, 1, 0),
227-
(0, -1, 0),
228-
(1, -1, 0),
229-
(-1, 1, 0),
230-
(0, 0, 123456),
231-
(0, 0, -123456),
232-
])
233+
@pytest.mark.parametrize(
234+
"args",
235+
[
236+
(0, 0, 0),
237+
(1, 0, 0),
238+
(-1, 0, 0),
239+
(0, 1, 0),
240+
(0, -1, 0),
241+
(1, -1, 0),
242+
(-1, 1, 0),
243+
(0, 0, 123456),
244+
(0, 0, -123456),
245+
],
246+
)
233247
def test_delta(args):
234248
act = pdt.timedelta(*args)
235249
exp = rdt.make_delta(*args)
@@ -245,24 +259,29 @@ def test_delta_accessors(td):
245259
assert act == exp
246260

247261

248-
@pytest.mark.parametrize('args,err_type', [
249-
((MAX_DAYS + 1, 0, 0), OverflowError),
250-
((MIN_DAYS - 1, 0, 0), OverflowError),
251-
((0, MAX_SECONDS + 1, 0), OverflowError),
252-
((0, MIN_SECONDS - 1, 0), OverflowError),
253-
((0, 0, MAX_MICROSECONDS + 1), OverflowError),
254-
((0, 0, MIN_MICROSECONDS - 1), OverflowError),
255-
(('0', 0, 0), TypeError),
256-
((0, '0', 0), TypeError),
257-
((0, 0, '0'), TypeError),
258-
])
262+
@pytest.mark.parametrize(
263+
"args,err_type",
264+
[
265+
((MAX_DAYS + 1, 0, 0), OverflowError),
266+
((MIN_DAYS - 1, 0, 0), OverflowError),
267+
((0, MAX_SECONDS + 1, 0), OverflowError),
268+
((0, MIN_SECONDS - 1, 0), OverflowError),
269+
((0, 0, MAX_MICROSECONDS + 1), OverflowError),
270+
((0, 0, MIN_MICROSECONDS - 1), OverflowError),
271+
(("0", 0, 0), TypeError),
272+
((0, "0", 0), TypeError),
273+
((0, 0, "0"), TypeError),
274+
],
275+
)
259276
def test_delta_err(args, err_type):
260277
with pytest.raises(err_type):
261278
rdt.make_delta(*args)
262279

280+
263281
def test_issue_219():
264282
rdt.issue_219()
265283

284+
266285
def test_tz_class():
267286
tzi = rdt.TzClass()
268287

@@ -272,9 +291,9 @@ def test_tz_class():
272291
assert dt.utcoffset() == pdt.timedelta(hours=1)
273292
assert dt.dst() is None
274293

294+
275295
def test_tz_class_introspection():
276296
tzi = rdt.TzClass()
277297

278298
assert tzi.__class__ == rdt.TzClass
279-
assert repr(tzi).startswith('<rustapi_module.datetime.TzClass object at')
280-
299+
assert repr(tzi).startswith("<rustapi_module.datetime.TzClass object at")

0 commit comments

Comments
 (0)