Skip to content

Commit 8d01094

Browse files
committed
bump edition to 2021, add msrv 1.56, test coverage
1 parent 573254d commit 8d01094

5 files changed

Lines changed: 88 additions & 32 deletions

File tree

.github/workflows/ci.yml

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,22 @@ jobs:
3131

3232
build:
3333
needs: [fmt] # don't wait for clippy as fails rarely and takes longer
34-
name: python${{ matrix.python-version }} ${{ matrix.platform.os }}
35-
runs-on: ${{ matrix.platform.os }}
34+
name: python${{ matrix.python-version }} ${{ matrix.os }} rust-${{ matrix.rust}}
35+
runs-on: ${{ matrix.os }}
3636
strategy:
3737
fail-fast: false # If one platform fails, allow the rest to keep testing.
3838
matrix:
3939
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
40-
platform: [
41-
{ os: "macOS-latest", rust-target: "x86_64-apple-darwin" },
42-
{ os: "ubuntu-latest", rust-target: "x86_64-unknown-linux-gnu" },
43-
{ os: "windows-latest", rust-target: "x86_64-pc-windows-msvc" },
40+
os: [
41+
"macos-latest",
42+
"ubuntu-latest",
43+
"windows-latest",
4444
]
45+
rust: [stable]
46+
include:
47+
- python-version: "3.12"
48+
os: "ubuntu-latest"
49+
rust: "1.56"
4550

4651
steps:
4752
- uses: actions/checkout@v4
@@ -53,12 +58,15 @@ jobs:
5358
architecture: x64
5459

5560
- name: Install Rust toolchain
56-
uses: dtolnay/rust-toolchain@stable
61+
uses: dtolnay/rust-toolchain@master
5762
with:
58-
target: ${{ matrix.platform.rust-target }}
63+
toolchain: ${{ matrix.rust }}
5964

60-
- name: Build without default features
61-
run: cargo test --no-default-features --verbose --target ${{ matrix.platform.rust-target }}
65+
- uses: Swatinem/rust-cache@v2
66+
continue-on-error: true
67+
68+
- name: Test
69+
run: cargo test --verbose
6270

6371
env:
6472
RUST_BACKTRACE: 1
@@ -68,13 +76,7 @@ jobs:
6876
runs-on: ubuntu-latest
6977
steps:
7078
- uses: actions/checkout@v4
71-
- uses: actions/cache@v3
72-
with:
73-
path: |
74-
~/.cargo/registry
75-
~/.cargo/git
76-
target
77-
key: coverage-cargo-${{ hashFiles('**/Cargo.toml') }}
79+
- uses: Swatinem/rust-cache@v2
7880
continue-on-error: true
7981
- name: Install cargo-llvm-cov
8082
uses: taiki-e/install-action@cargo-llvm-cov

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## Unreleased
2+
3+
- Bump edition to 2021
4+
- Bump MSRV to 1.56
5+
16
## 0.20.0 - 2023-10-15
27

38
- Update to PyO3 0.20

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
name = "pythonize"
33
version = "0.20.0"
44
authors = ["David Hewitt <1939362+davidhewitt@users.noreply.github.com>"]
5-
edition = "2018"
5+
edition = "2021"
6+
rust-version = "1.56"
67
license = "MIT"
78
description = "Serde Serializer & Deserializer from Rust <--> Python, backed by PyO3."
89
homepage = "https://github.com/davidhewitt/pythonize"

src/de.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,16 +75,12 @@ impl<'a, 'de> de::Deserializer<'de> for &'a mut Depythonizer<'de> {
7575
self.deserialize_i64(visitor)
7676
} else if obj.is_instance_of::<PyList>() {
7777
self.deserialize_tuple(obj.len()?, visitor)
78-
} else if obj.is_instance_of::<PyLong>() {
79-
self.deserialize_i64(visitor)
8078
} else if obj.is_instance_of::<PySet>() {
8179
self.deserialize_tuple(obj.len()?, visitor)
8280
} else if obj.is_instance_of::<PyString>() {
8381
self.deserialize_str(visitor)
8482
} else if obj.is_instance_of::<PyTuple>() {
8583
self.deserialize_tuple(obj.len()?, visitor)
86-
} else if obj.is_instance_of::<PyUnicode>() {
87-
self.deserialize_str(visitor)
8884
} else if obj.downcast::<PySequence>().is_ok() {
8985
self.deserialize_tuple(obj.len()?, visitor)
9086
} else if obj.downcast::<PyMapping>().is_ok() {
@@ -463,19 +459,22 @@ mod test {
463459
foo: String,
464460
bar: usize,
465461
baz: f32,
462+
qux: bool,
466463
}
467464

468465
let expected = Struct {
469466
foo: "Foo".to_string(),
470467
bar: 8usize,
471468
baz: 45.23,
469+
qux: true,
472470
};
473471
let expected_json = json!({
474472
"foo": "Foo",
475473
"bar": 8,
476-
"baz": 45.23
474+
"baz": 45.23,
475+
"qux": true
477476
});
478-
let code = "{'foo': 'Foo', 'bar': 8, 'baz': 45.23}";
477+
let code = "{'foo': 'Foo', 'bar': 8, 'baz': 45.23, 'qux': True}";
479478
test_de(code, &expected, &expected_json);
480479
}
481480

src/ser.rs

Lines changed: 57 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ mod test {
457457
use maplit::hashmap;
458458
use pyo3::types::PyDict;
459459
use pyo3::{PyResult, Python};
460-
use serde::{Deserialize, Serialize};
460+
use serde::Serialize;
461461

462462
fn test_ser<T>(src: T, expected: &str)
463463
where
@@ -486,15 +486,15 @@ mod test {
486486

487487
#[test]
488488
fn test_empty_struct() {
489-
#[derive(Serialize, Deserialize)]
489+
#[derive(Serialize)]
490490
struct Empty;
491491

492492
test_ser(Empty, "null");
493493
}
494494

495495
#[test]
496496
fn test_struct() {
497-
#[derive(Serialize, Deserialize)]
497+
#[derive(Serialize)]
498498
struct Struct {
499499
foo: String,
500500
bar: usize,
@@ -511,7 +511,7 @@ mod test {
511511

512512
#[test]
513513
fn test_tuple_struct() {
514-
#[derive(Serialize, Deserialize)]
514+
#[derive(Serialize)]
515515
struct TupleStruct(String, usize);
516516

517517
test_ser(TupleStruct("foo".to_string(), 5), r#"["foo",5]"#);
@@ -534,7 +534,7 @@ mod test {
534534

535535
#[test]
536536
fn test_enum_unit_variant() {
537-
#[derive(Serialize, Deserialize)]
537+
#[derive(Serialize)]
538538
enum E {
539539
Empty,
540540
}
@@ -544,7 +544,7 @@ mod test {
544544

545545
#[test]
546546
fn test_enum_tuple_variant() {
547-
#[derive(Serialize, Deserialize)]
547+
#[derive(Serialize)]
548548
enum E {
549549
Tuple(i32, String),
550550
}
@@ -554,7 +554,7 @@ mod test {
554554

555555
#[test]
556556
fn test_enum_newtype_variant() {
557-
#[derive(Serialize, Deserialize)]
557+
#[derive(Serialize)]
558558
enum E {
559559
NewType(String),
560560
}
@@ -564,7 +564,7 @@ mod test {
564564

565565
#[test]
566566
fn test_enum_struct_variant() {
567-
#[derive(Serialize, Deserialize)]
567+
#[derive(Serialize)]
568568
enum E {
569569
Struct { foo: String, bar: usize },
570570
}
@@ -577,4 +577,53 @@ mod test {
577577
r#"{"Struct":{"foo":"foo","bar":5}}"#,
578578
);
579579
}
580+
581+
#[test]
582+
fn test_integers() {
583+
#[derive(Serialize)]
584+
struct Integers {
585+
a: i8,
586+
b: i16,
587+
c: i32,
588+
d: i64,
589+
e: u8,
590+
f: u16,
591+
g: u32,
592+
h: u64,
593+
}
594+
595+
test_ser(
596+
Integers {
597+
a: 1,
598+
b: 2,
599+
c: 3,
600+
d: 4,
601+
e: 5,
602+
f: 6,
603+
g: 7,
604+
h: 8,
605+
},
606+
r#"{"a":1,"b":2,"c":3,"d":4,"e":5,"f":6,"g":7,"h":8}"#,
607+
)
608+
}
609+
610+
#[test]
611+
fn test_bool() {
612+
test_ser(true, "true");
613+
test_ser(false, "false");
614+
}
615+
616+
#[test]
617+
fn test_none() {
618+
#[derive(Serialize)]
619+
struct S;
620+
621+
test_ser((), "null");
622+
test_ser(S, "null");
623+
}
624+
625+
#[test]
626+
fn test_bytes() {
627+
test_ser(b"foo", "[102,111,111]");
628+
}
580629
}

0 commit comments

Comments
 (0)