Skip to content

Commit 7f49673

Browse files
author
Martin Larralde
authored
Merge pull request #149 from althonos/master
Fix `exception` tests failing with Python 2
2 parents b64977f + cc352da commit 7f49673

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

src/objects/exc_impl.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -116,12 +116,15 @@ mod test {
116116
let py = gil.python();
117117

118118
let err: PyErr = gaierror.into();
119+
let socket = py.import("socket").map_err(|e| e.print(py)).expect("could not import socket");
119120

120121
let d = PyDict::new(py);
121-
d.set_item("socket", py.import("socket").map_err(|e| e.print(py)).unwrap()).unwrap();
122-
d.set_item("exc", err).unwrap();
122+
d.set_item("socket", socket).map_err(|e| e.print(py)).expect("could not setitem");
123+
d.set_item("exc", err).map_err(|e| e.print(py)).expect("could not setitem");
123124

124-
py.run("assert isinstance(exc, socket.gaierror)", None, Some(d)).unwrap();
125+
py.run("assert isinstance(exc, socket.gaierror)", None, Some(d))
126+
.map_err(|e| e.print(py))
127+
.expect("assertion failed");
125128
}
126129

127130
#[test]
@@ -130,11 +133,14 @@ mod test {
130133
let py = gil.python();
131134

132135
let err: PyErr = MessageError.into();
136+
let email = py.import("email").map_err(|e| e.print(py)).expect("could not import email");
133137

134138
let d = PyDict::new(py);
135-
d.set_item("email", py.import("email").map_err(|e| e.print(py)).unwrap()).unwrap();
136-
d.set_item("exc", err).unwrap();
139+
d.set_item("email", email).map_err(|e| e.print(py)).expect("could not setitem");
140+
d.set_item("exc", err).map_err(|e| e.print(py)).expect("could not setitem");
137141

138-
py.run("assert isinstance(exc, email.errors.MessageError)", None, Some(d)).unwrap();
142+
py.run("assert isinstance(exc, email.errors.MessageError)", None, Some(d))
143+
.map_err(|e| e.print(py))
144+
.expect("assertion failed");
139145
}
140146
}

0 commit comments

Comments
 (0)