Skip to content

Commit 41e8fef

Browse files
committed
Support python3.5
1 parent 49460dd commit 41e8fef

9 files changed

Lines changed: 101 additions & 6 deletions

File tree

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ classifier = [
2626
"Operating System :: Microsoft :: Windows",
2727
"Operating System :: POSIX :: Linux",
2828
"Programming Language :: Python :: 3",
29+
"Programming Language :: Python :: 3.5",
2930
"Programming Language :: Python :: 3.6",
3031
"Programming Language :: Python :: 3.7",
3132
"Programming Language :: Python :: 3.8",

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ conformance on NaN/Infinity/-Infinity, having an option for strict
1717
JSON conformance on 53-bit integers, not supporting pretty
1818
printing, and not supporting all standard library options.
1919

20-
It supports CPython 3.6 and 3.7 and distributes wheels for Linux, macOS, and
21-
Windows. The repository and issue tracker is
20+
It supports CPython 3.5, 3.6, 3.7, and 3.8. It distributes wheels for Linux,
21+
macOS, and Windows. The repository and issue tracker is
2222
[github.com/ijl/orjson](https://github.com/ijl/orjson).
2323

2424
## Usage

ci/azure-pipelines.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,23 @@ jobs:
3434
dependencies: apt
3535
- template: ./azure-posix.yml
3636

37+
- job: linux_python35
38+
pool:
39+
vmImage: ubuntu-16.04
40+
variables:
41+
interpreter: python3.5
42+
target: x86_64-unknown-linux-gnu
43+
steps:
44+
- task: UsePythonVersion@0
45+
inputs:
46+
versionSpec: '3.5'
47+
addToPath: true
48+
- checkout: self
49+
- template: ./azure-linux.yml
50+
parameters:
51+
dependencies: apt
52+
- template: ./azure-posix.yml
53+
3754
- job: macos_python37
3855
pool:
3956
vmImage: xcode9-macos10.13
@@ -64,6 +81,21 @@ jobs:
6481
- template: ./azure-macos.yml
6582
- template: ./azure-posix.yml
6683

84+
- job: macos_python35
85+
pool:
86+
vmImage: xcode9-macos10.13
87+
variables:
88+
interpreter: python3.5
89+
target: x86_64-apple-darwin
90+
steps:
91+
- task: UsePythonVersion@0
92+
inputs:
93+
versionSpec: '3.5'
94+
addToPath: true
95+
- checkout: self
96+
- template: ./azure-macos.yml
97+
- template: ./azure-posix.yml
98+
6799
- job: win_python37
68100
pool:
69101
vmImage: vs2017-win2016
@@ -93,3 +125,19 @@ jobs:
93125
architecture: 'x64'
94126
- checkout: self
95127
- template: ./azure-win.yml
128+
129+
- job: win_python35
130+
pool:
131+
vmImage: vs2017-win2016
132+
variables:
133+
interpreter: C:\hostedtoolcache\windows\Python\3.5.4\x64\python.exe
134+
target: x86_64-pc-windows-msvc
135+
steps:
136+
- task: UsePythonVersion@0
137+
inputs:
138+
versionSpec: '3.5'
139+
addToPath: true
140+
architecture: 'x64'
141+
- checkout: self
142+
- template: ./azure-win.yml
143+

src/encode.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,12 @@ impl<'p> Serialize for SerializePyObject {
199199
std::ptr::null_mut() as *mut pyo3::ffi::PyObject,
200200
)
201201
};
202+
// test_datetime_partial_second_pendulum_not_supported
203+
if offset.is_null() {
204+
return Err(ser::Error::custom(
205+
"datetime does not support timezones with offsets that are not even minutes",
206+
));
207+
}
202208
offset_second =
203209
unsafe { pyo3::ffi::PyDateTime_DELTA_GET_SECONDS(offset) as i32 };
204210
offset_day = unsafe { pyo3::ffi::PyDateTime_DELTA_GET_DAYS(offset) };

test/test_api.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ def test_option_range_high(self):
9292
with self.assertRaises(orjson.JSONEncodeError):
9393
orjson.dumps(True, option=4)
9494

95-
9695
def test_opts_multiple(self):
9796
"""
9897
dumps() multiple option

test/test_datetime.py

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22

33
import unittest
44
import datetime
5+
import sys
56

67
import arrow
78
import orjson
89
import pendulum
10+
import pytest
911
import pytz
1012
from dateutil import tz
1113

@@ -154,7 +156,8 @@ def test_datetime_pendulum_partial_hour(self):
154156
b'["2018-12-01T02:03:04+10:30"]',
155157
)
156158

157-
def test_datetime_partial_second(self):
159+
@pytest.mark.skipif(sys.version_info.minor == 5, reason="Non-even minute offsets supported on not 3.5")
160+
def test_datetime_partial_second_pendulum_supported(self):
158161
"""
159162
datetime.datetime UTC offset round seconds
160163
@@ -165,6 +168,38 @@ def test_datetime_partial_second(self):
165168
b'["1937-01-01T12:00:27.87+00:20"]',
166169
)
167170

171+
@pytest.mark.skipif(sys.version_info.minor != 5, reason="Non-even minute offsets not supported on 3.5")
172+
def test_datetime_partial_second_pendulum_not_supported(self):
173+
"""
174+
datetime.datetime UTC offset round seconds
175+
176+
https://tools.ietf.org/html/rfc3339#section-5.8
177+
"""
178+
with self.assertRaises(orjson.JSONEncodeError):
179+
orjson.dumps([datetime.datetime(1937, 1, 1, 12, 0, 27, 87, tzinfo=pendulum.timezone('Europe/Amsterdam'))])
180+
181+
def test_datetime_partial_second_pytz(self):
182+
"""
183+
datetime.datetime UTC offset round seconds
184+
185+
https://tools.ietf.org/html/rfc3339#section-5.8
186+
"""
187+
self.assertEqual(
188+
orjson.dumps([datetime.datetime(1937, 1, 1, 12, 0, 27, 87, tzinfo=pytz.timezone('Europe/Amsterdam'))]),
189+
b'["1937-01-01T12:00:27.87+00:20"]',
190+
)
191+
192+
def test_datetime_partial_second_dateutil(self):
193+
"""
194+
datetime.datetime UTC offset round seconds
195+
196+
https://tools.ietf.org/html/rfc3339#section-5.8
197+
"""
198+
self.assertEqual(
199+
orjson.dumps([datetime.datetime(1937, 1, 1, 12, 0, 27, 87, tzinfo=tz.gettz('Europe/Amsterdam'))]),
200+
b'["1937-01-01T12:00:27.87+00:20"]',
201+
)
202+
168203

169204
class DateTests(unittest.TestCase):
170205

test/test_jsonchecker.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,13 @@
22
"""
33
Tests files from http://json.org/JSON_checker/
44
"""
5-
from __future__ import division, print_function, unicode_literals
65

76
import unittest
87
import os
98
import sys
109

1110
import orjson
12-
11+
import pytest
1312

1413
_path = os.path.join(os.path.dirname(__file__), '..', 'data', 'jsonchecker')
1514

@@ -237,6 +236,7 @@ def test_fail33(self):
237236
"""
238237
self._run_fail_json('fail33.json')
239238

239+
@pytest.mark.skipif(sys.version_info < (3,6), reason="Indeterminate key order")
240240
def test_pass01(self):
241241
"""
242242
pass01.json
@@ -255,6 +255,7 @@ def test_pass02(self):
255255
b'[[[[[[[[[[[[[[[[[[["Not too deep"]]]]]]]]]]]]]]]]]]]'
256256
)
257257

258+
@pytest.mark.skipif(sys.version_info < (3,6), reason="Indeterminate key order")
258259
def test_pass03(self):
259260
"""
260261
pass03.json

test/test_roundtrip.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import sys
66

77
import orjson
8+
import pytest
89

910
_path = os.path.join(os.path.dirname(__file__), '..', 'data', 'roundtrip')
1011

@@ -75,6 +76,7 @@ def test_roundtrip009(self):
7576
"""
7677
self._run_roundtrip_json('roundtrip09.json')
7778

79+
@pytest.mark.skipif(sys.version_info < (3,6), reason="Indeterminate key order")
7880
def test_roundtrip010(self):
7981
"""
8082
roundtrip010.json

test/test_ujson.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import unittest
1010

1111
import orjson
12+
import pytest
1213

1314

1415
class UltraJSONTests(unittest.TestCase):
@@ -346,12 +347,14 @@ def test_decodeNullCharacter(self):
346347
input = "\"31337 \\u0000 31337\""
347348
self.assertEqual(orjson.loads(input), json.loads(input))
348349

350+
@pytest.mark.skipif(sys.version_info < (3,6), reason="Bytes input not supported in older Python versions")
349351
def test_decodeEscape(self):
350352
base = '\u00e5'.encode('utf-8')
351353
quote = "\"".encode()
352354
input = quote + base + quote
353355
self.assertEqual(json.loads(input), orjson.loads(input))
354356

357+
@pytest.mark.skipif(sys.version_info < (3,6), reason="Bytes input not supported in older Python versions")
355358
def test_decodeBigEscape(self):
356359
for _ in range(10):
357360
base = '\u00e5'.encode('utf-8')

0 commit comments

Comments
 (0)