mirror of
https://github.com/RustPython/RustPython.git
synced 2026-06-02 19:39:49 +09:00
Fix time.strptime (#6208)
This commit is contained in:
2
Lib/test/test_time.py
vendored
2
Lib/test/test_time.py
vendored
@@ -284,8 +284,6 @@ class TimeTestCase(unittest.TestCase):
|
||||
self.assertRaises(TypeError, time.strptime, b'2009', "%Y")
|
||||
self.assertRaises(TypeError, time.strptime, '2009', b'%Y')
|
||||
|
||||
# TODO: RUSTPYTHON
|
||||
@unittest.expectedFailure
|
||||
def test_strptime_exception_context(self):
|
||||
# check that this doesn't chain exceptions needlessly (see #17572)
|
||||
with self.assertRaises(ValueError) as e:
|
||||
|
||||
6
Lib/test/test_zipfile.py
vendored
6
Lib/test/test_zipfile.py
vendored
@@ -123,8 +123,6 @@ class AbstractTestsWithSourceFile:
|
||||
# Check that testzip doesn't raise an exception
|
||||
zipfp.testzip()
|
||||
|
||||
# TODO: RUSTPYTHON
|
||||
@unittest.expectedFailure
|
||||
def test_basic(self):
|
||||
for f in get_files(self):
|
||||
self.zip_test(f, self.compression)
|
||||
@@ -394,8 +392,6 @@ class AbstractTestsWithSourceFile:
|
||||
self.assertIn('[closed]', repr(zipopen))
|
||||
self.assertIn('[closed]', repr(zipfp))
|
||||
|
||||
# TODO: RUSTPYTHON
|
||||
@unittest.expectedFailure
|
||||
def test_compresslevel_basic(self):
|
||||
for f in get_files(self):
|
||||
self.zip_test(f, self.compression, compresslevel=9)
|
||||
@@ -751,8 +747,6 @@ class AbstractTestZip64InSmallFiles:
|
||||
# Check that testzip doesn't raise an exception
|
||||
zipfp.testzip()
|
||||
|
||||
# TODO: RUSTPYTHON
|
||||
@unittest.expectedFailure
|
||||
def test_basic(self):
|
||||
for f in get_files(self):
|
||||
self.zip_test(f, self.compression)
|
||||
|
||||
@@ -364,15 +364,16 @@ mod decl {
|
||||
}
|
||||
|
||||
#[pyfunction]
|
||||
fn strptime(
|
||||
string: PyStrRef,
|
||||
format: OptionalArg<PyStrRef>,
|
||||
vm: &VirtualMachine,
|
||||
) -> PyResult<PyStructTime> {
|
||||
let format = format.as_ref().map_or("%a %b %H:%M:%S %Y", |s| s.as_str());
|
||||
let instant = NaiveDateTime::parse_from_str(string.as_str(), format)
|
||||
.map_err(|e| vm.new_value_error(format!("Parse error: {e:?}")))?;
|
||||
Ok(PyStructTime::new(vm, instant, -1))
|
||||
fn strptime(string: PyStrRef, format: OptionalArg<PyStrRef>, vm: &VirtualMachine) -> PyResult {
|
||||
// Call _strptime._strptime_time like CPython does
|
||||
let strptime_module = vm.import("_strptime", 0)?;
|
||||
let strptime_func = strptime_module.get_attr("_strptime_time", vm)?;
|
||||
|
||||
// Call with positional arguments
|
||||
match format.into_option() {
|
||||
Some(fmt) => strptime_func.call((string, fmt), vm),
|
||||
None => strptime_func.call((string,), vm),
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(any(
|
||||
|
||||
Reference in New Issue
Block a user