8000 Fix remaining tests · RustPython/RustPython@f239de0 · GitHub
[go: up one dir, main page]

Skip to content

Commit f239de0

Browse files
committed
Fix remaining tests
1 parent 8ed29d1 commit f239de0

File tree

19 files changed

+150
-106
lines changed

19 files changed

+150
-106
lines changed

Lib/test/string_tests.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1066,8 +1066,6 @@ def test_hash(self):
10661066
hash(b)
10671067
self.assertEqual(hash(a), hash(b))
10681068

1069-
# TODO: RUSTPYTHON
1070-
@unittest.expectedFailure
10711069
def test_capitalize_nonascii(self):
10721070
# check that titlecased chars are lowered correctly
10731071
# \u1ffc is the titlecased char

Lib/test/test_cmd_line_script.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -574,8 +574,7 @@ def test_pep_409_verbiage(self):
574574
self.assertTrue(text[1].startswith(' File '))
575575
self.assertTrue(text[3].startswith('NameError'))
576576

577-
# TODO: RUSTPYTHON
578-
@unittest.expectedFailure
577+
@unittest.expectedFailureIf(sys.platform == "linux", "TODO: RUSTPYTHON")
579578
def test_non_ascii(self):
580579
# Mac OS X denies the creation of a file with an invalid UTF-8 name.
581580
# Windows allows creating a name with an arbitrary bytes name, but

Lib/test/test_import/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1305,6 +1305,8 @@ def exec_module(*args):
13051305
else:
13061306
importlib.SourceLoader.exec_module = old_exec_module
13071307

1308+
# TODO: RUSTPYTHON
1309+
@unittest.expectedFailure
13081310
@unittest.skipUnless(TESTFN_UNENCODABLE, 'need TESTFN_UNENCODABLE')
13091311
def test_unencodable_filename(self):
13101312
# Issue #11619: The Python parser and the import machinery must not

Lib/test/test_json/test_scanstring.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,4 @@ def test_overflow(self):
143143

144144

145145
class TestPyScanstring(TestScanstring, PyTest): pass
146-
# TODO: RUSTPYTHON
147-
class TestPyScanstring(TestScanstring, PyTest):
148-
# TODO: RUSTPYTHON
149-
@unittest.expectedFailure
150-
def test_bad_escapes(self):
151-
super().test_bad_escapes()
152146
class TestCScanstring(TestScanstring, CTest): pass

Lib/test/test_ntpath.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1032,12 +1032,6 @@ class NtCommonTest(test_genericpath.CommonTest, unittest.TestCase):
10321032
pathmodule = ntpath
10331033
attributes = ['relpath']
10341034

1035-
# TODO: RUSTPYTHON
1036-
if sys.platform == "linux":
1037-
@unittest.expectedFailure
1038-
def test_nonascii_abspath(self):
1039-
super().test_nonascii_abspath()
1040-
10411035
# TODO: RUSTPYTHON
10421036
if sys.platform == "win32":
10431037
# TODO: RUSTPYTHON, ValueError: illegal environment variable name

Lib/test/test_re.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2231,6 +2231,7 @@ def test_bug_40736(self):
22312231
with self.assertRaisesRegex(TypeError, "got 'type'"):
22322232
re.search("x*", type)
22332233

2234+
@unittest.skip("TODO: RUSTPYTHON: flaky, improve perf")
22342235
@requires_resource('cpu')
22352236
def test_search_anchor_at_beginning(self):
22362237
s = 'x'*10**7

Lib/test/test_socket.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1578,6 +1578,7 @@ def test_getnameinfo(self):
15781578
# only IP addresses are allowed
15791579
self.assertRaises(OSError, socket.getnameinfo, ('mail.python.org',0), 0)
15801580

1581+
@unittest.skip("TODO: RUSTPYTHON: flaky on CI?")
15811582
@unittest.skipUnless(support.is_resource_enabled('network'),
15821583
'network is not enabled')
15831584
def test_idna(self):

Lib/test/test_sqlite3/test_types.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,6 @@ def test_too_large_int(self):
9595
row = self.cur.fetchone()
9696
self.assertIsNone(row)
9797

98-
# TODO: RUSTPYTHON
99-
@unittest.expectedFailure
10098
def test_string_with_surrogates(self):
10199
for value in 0xd8ff, 0xdcff:
102100
with self.assertRaises(UnicodeEncodeError):

Lib/test/test_ucn.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,6 @@ def test_cjk_unified_ideographs(self):
102102
self.checkletter("CJK UNIFIED IDEOGRAPH-2B81D", "\U0002B81D")
103103
self.checkletter("CJK UNIFIED IDEOGRAPH-3134A", "\U0003134A")
104104

105-
# TODO: RUSTPYTHON
106-
@unittest.expectedFailure
107105
def test_bmp_characters(self):
108106
for code in range(0x10000):
109107
char = chr(code)

Lib/test/test_unicode.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -721,8 +721,6 @@ def test_isspace(self):
721721
'\U0001F40D', '\U0001F46F']:
722722
self.assertFalse(ch.isspace(), '{!a} is not space.'.format(ch))
723723

724-
# TODO: RUSTPYTHON
725-
@unittest.expectedFailure
726724
@support.requires_resource('cpu')
727725
def test_isspace_invariant(self):
728726
for codepoint in range(sys.maxunicode + 1):

Lib/test/test_unicodedata.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,6 @@ def test_function_checksum(self):
9999
result = h.hexdigest()
100100
self.assertEqual(result, self.expectedchecksum)
101101

102-
# TODO: RUSTPYTHON
103-
@unittest.expectedFailure
104102
@requires_resource('cpu')
105103
def test_name_inverse_lookup(self):
106104
for i in range(sys.maxunicode + 1):
@@ -326,8 +324,6 @@ def test_ucd_510(self):
326324
self.assertTrue("\u1d79".upper()=='\ua77d')
327325
self.assertTrue(".".upper()=='.')
328326

329-
# TODO: RUSTPYTHON
330-
@unittest.expectedFailure
331327
def test_bug_5828(self):
332328
self.assertEqual("\u1d79".lower(), "\u1d79")
333329
# Only U+0000 should have U+0000 as its upper/lower/titlecase variant
@@ -347,8 +343,6 @@ def test_bug_4971(self):
347343
self.assertEqual("\u01c5".title(), "\u01c5")
348344
self.assertEqual("\u01c6".title(), "\u01c5")
349345

350-
# TODO: RUSTPYTHON
351-
@unittest.expectedFailure
352346
def test_linebreak_7643(self):
353347
for i in range(0x10000):
354348
lines = (chr(i) + 'A').splitlines()

common/src/wtf8/mod.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,12 @@ impl Extend<CodePoint> for Wtf8Buf {
552552
}
553553
}
554554

555+
impl Extend<char> for Wtf8Buf {
556+
fn extend<T: IntoIterator<Item = char>>(&mut self, iter: T) {
557+
self.extend(iter.into_iter().map(CodePoint::from))
558+
}
559+
}
560+
555561
impl<W: AsRef<Wtf8>> Extend<W> for Wtf8Buf {
556562
fn extend<T: IntoIterator<Item = W>>(&mut self, iter: T) {
557563
iter.into_iter()
@@ -1004,6 +1010,14 @@ impl Wtf8 {
10041010
memchr::memmem::rfind(self.as_bytes(), pat.as_bytes())
10051011
}
10061012

1013+
pub fn find_iter(&self, pat: &Wtf8) -> impl Iterator<Item = usize> {
1014+
memchr::memmem::find_iter(self.as_bytes(), pat.as_bytes())
1015+
}
1016+
1017+
pub fn rfind_iter(&self, pat: &Wtf8) -> impl Iterator<Item = usize> {
1018+
memchr::memmem::rfind_iter(self.as_bytes(), pat.as_bytes())
1019+
}
1020+
10071021
pub fn contains(&self, pat: &Wtf8) -> bool {
10081022
self.bytes.contains_str(pat)
10091023
}
@@ -1057,6 +1071,11 @@ impl Wtf8 {
10571071
let w = self.bytes.replace(from, to);
10581072
unsafe { Wtf8Buf::from_bytes_unchecked(w) }
10591073
}
1074+
1075+
pub fn replacen(&self, from: &Wtf8, to: &Wtf8, n: usize) -> Wtf8Buf {
1076+
let w = self.bytes.replacen(from, to, n);
1077+
unsafe { Wtf8Buf::from_bytes_unchecked(w) }
1078+
}
10601079
}
10611080

10621081
impl AsRef<Wtf8> for str {

stdlib/src/sqlite.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2929,9 +2929,12 @@ mod _sqlite {
29292929
}
29302930

29312931
fn str_to_ptr_len(s: &PyStr, vm: &VirtualMachine) -> PyResult<(*const libc::c_char, i32)> {
2932-
let len = c_int::try_from(s.byte_len())
2932+
let s = s
2933+
.to_str()
2934+
.ok_or_else(|| vm.new_unicode_encode_error("surrogates not allowed".to_owned()))?;
2935+
let len = c_int::try_from(s.len())
29332936
.map_err(|_| vm.new_overflow_error("TEXT longer than INT_MAX bytes".to_owned()))?;
2934-
let ptr = s.as_str().as_ptr().cast();
2937+
let ptr = s.as_ptr().cast();
29352938
Ok((ptr, len))
29362939
}
29372940

stdlib/src/ssl.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -403,8 +403,8 @@ mod _ssl {
403403
.to_str()
404404
.unwrap();
405405
let (cert_file, cert_dir) = get_cert_file_dir();
406-
let cert_file = OsPath::new_str(cert_file).filename(vm)?;
407-
let cert_dir = OsPath::new_str(cert_dir).filename(vm)?;
406+
let cert_file = OsPath::new_str(cert_file).filename(vm);
407+
let cert_dir = OsPath::new_str(cert_dir).filename(vm);
408408
Ok((cert_file_env, cert_file, cert_dir_env, cert_dir))
409409
}
410410

0 commit comments

Comments
 (0)
0