Skip to content

Commit c3754cd

Browse files
authored
Merge pull request #6049 from youknowone/fix-support
Fix test.support.requires_debug_ranges
2 parents f32a5b1 + f8891ff commit c3754cd

File tree

3 files changed

+66
-16
lines changed

3 files changed

+66
-16
lines changed

Lib/test/support/__init__.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,12 @@ def has_no_debug_ranges():
514514
return not bool(config['code_debug_ranges'])
515515

516516
def requires_debug_ranges(reason='requires co_positions / debug_ranges'):
517-
return unittest.skipIf(has_no_debug_ranges(), reason)
517+
try:
518+
skip = has_no_debug_ranges()
519+
except unittest.SkipTest as e:
520+
skip = True
521+
reason = e.args[0] if e.args else reason
522+
return unittest.skipIf(skip, reason)
518523

519524
@contextlib.contextmanager
520525
def suppress_immortalization(suppress=True):

Lib/test/test_compile.py

Lines changed: 48 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,6 @@ def f(x):
138138
def test_argument_order(self):
139139
self.assertRaises(SyntaxError, exec, 'def f(a=1, b): pass')
140140

141-
@unittest.skip("TODO: RUSTPYTHON, thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: ParseFloatError { kind: Invalid }'")
142141
def test_float_literals(self):
143142
# testing bad float literals
144143
self.assertRaises(SyntaxError, eval, "2e")
@@ -201,6 +200,8 @@ def test_literals_with_leading_zeroes(self):
201200
self.assertEqual(eval("0o777"), 511)
202201
self.assertEqual(eval("-0o0000010"), -8)
203202

203+
# TODO: RUSTPYTHON
204+
@unittest.expectedFailure
204205
def test_int_literals_too_long(self):
205206
n = 3000
206207
source = f"a = 1\nb = 2\nc = {'3'*n}\nd = 4"
@@ -274,6 +275,8 @@ def test_none_assignment(self):
274275
self.assertRaises(SyntaxError, compile, stmt, 'tmp', 'single')
275276
self.assertRaises(SyntaxError, compile, stmt, 'tmp', 'exec')
276277

278+
# TODO: RUSTPYTHON
279+
@unittest.expectedFailure
277280
def test_import(self):
278281
succeed = [
279282
'import sys',
@@ -821,6 +824,8 @@ def continue_in_while():
821824
self.assertEqual(None, opcodes[1].argval)
822825
self.assertEqual('RETURN_VALUE', opcodes[2].opname)
823826

827+
# TODO: RUSTPYTHON
828+
@unittest.expectedFailure
824829
def test_consts_in_conditionals(self):
825830
def and_true(x):
826831
return True and x
@@ -844,6 +849,8 @@ def or_false(x):
844849
self.assertIn('LOAD_', opcodes[-2].opname)
845850
self.assertEqual('RETURN_VALUE', opcodes[-1].opname)
846851

852+
# TODO: RUSTPYTHON
853+
@unittest.expectedFailure
847854
def test_imported_load_method(self):
848855
sources = [
849856
"""\
@@ -878,6 +885,8 @@ def foo(x):
878885
self.assertIn('LOAD_ATTR', instructions)
879886
self.assertIn('PRECALL', instructions)
880887

888+
# TODO: RUSTPYTHON
889+
@unittest.expectedFailure
881890
def test_lineno_procedure_call(self):
882891
def call():
883892
(
@@ -886,6 +895,8 @@ def call():
886895
line1 = call.__code__.co_firstlineno + 1
887896
assert line1 not in [line for (_, _, line) in call.__code__.co_lines()]
888897

898+
# TODO: RUSTPYTHON
899+
@unittest.expectedFailure
889900
def test_lineno_after_implicit_return(self):
890901
TRUE = True
891902
# Don't use constant True or False, as compiler will remove test
@@ -920,6 +931,8 @@ def save_caller_frame():
920931
func(save_caller_frame)
921932
self.assertEqual(frame.f_lineno-frame.f_code.co_firstlineno, lastline)
922933

934+
# TODO: RUSTPYTHON
935+
@unittest.expectedFailure
923936
def test_lineno_after_no_code(self):
924937
def no_code1():
925938
"doc string"
@@ -944,6 +957,8 @@ def get_code_lines(self, code):
944957
last_line = line
945958
return res
946959

960+
# TODO: RUSTPYTHON
961+
@unittest.expectedFailure
947962
def test_lineno_attribute(self):
948963
def load_attr():
949964
return (
@@ -988,6 +1003,8 @@ def aug_store_attr():
9881003
code_lines = self.get_code_lines(func.__code__)
9891004
self.assertEqual(lines, code_lines)
9901005

1006+
# TODO: RUSTPYTHON
1007+
@unittest.expectedFailure
9911008
def test_line_number_genexp(self):
9921009

9931010
def return_genexp():
@@ -1002,6 +1019,8 @@ def return_genexp():
10021019
code_lines = self.get_code_lines(genexp_code)
10031020
self.assertEqual(genexp_lines, code_lines)
10041021

1022+
# TODO: RUSTPYTHON
1023+
@unittest.expectedFailure
10051024
def test_line_number_implicit_return_after_async_for(self):
10061025

10071026
async def test(aseq):
@@ -1022,6 +1041,8 @@ def test_big_dict_literal(self):
10221041
the_dict = "{" + ",".join(f"{x}:{x}" for x in range(dict_size)) + "}"
10231042
self.assertEqual(len(eval(the_dict)), dict_size)
10241043

1044+
# TODO: RUSTPYTHON
1045+
@unittest.expectedFailure
10251046
def test_redundant_jump_in_if_else_break(self):
10261047
# Check if bytecode containing jumps that simply point to the next line
10271048
# is generated around if-else-break style structures. See bpo-42615.
@@ -1051,6 +1072,8 @@ def if_else_break():
10511072
elif instr.opname in HANDLED_JUMPS:
10521073
self.assertNotEqual(instr.arg, (line + 1)*INSTR_SIZE)
10531074

1075+
# TODO: RUSTPYTHON
1076+
@unittest.expectedFailure
10541077
def test_no_wraparound_jump(self):
10551078
# See https://bugs.python.org/issue46724
10561079

@@ -1061,6 +1084,8 @@ def while_not_chained(a, b, c):
10611084
for instr in dis.Bytecode(while_not_chained):
10621085
self.assertNotEqual(instr.opname, "EXTENDED_ARG")
10631086

1087+
# TODO: RUSTPYTHON
1088+
@unittest.expectedFailure
10641089
def test_compare_positions(self):
10651090
for opname, op in [
10661091
("COMPARE_OP", "<"),
@@ -1361,64 +1386,66 @@ def check_stack_size(self, code):
13611386
max_size = math.ceil(math.log(len(code.co_code)))
13621387
self.assertLessEqual(code.co_stacksize, max_size)
13631388

1364-
# TODO: RUSTPYTHON
1365-
@unittest.expectedFailure
13661389
def test_and(self):
13671390
self.check_stack_size("x and " * self.N + "x")
13681391

1369-
# TODO: RUSTPYTHON
1370-
@unittest.expectedFailure
13711392
def test_or(self):
13721393
self.check_stack_size("x or " * self.N + "x")
13731394

1374-
# TODO: RUSTPYTHON
1375-
@unittest.expectedFailure
13761395
def test_and_or(self):
13771396
self.check_stack_size("x and x or " * self.N + "x")
13781397

1379-
# TODO: RUSTPYTHON
1380-
@unittest.expectedFailure
13811398
def test_chained_comparison(self):
13821399
self.check_stack_size("x < " * self.N + "x")
13831400

1384-
# TODO: RUSTPYTHON
1385-
@unittest.expectedFailure
13861401
def test_if_else(self):
13871402
self.check_stack_size("x if x else " * self.N + "x")
13881403

1389-
# TODO: RUSTPYTHON
1390-
@unittest.expectedFailure
13911404
def test_binop(self):
13921405
self.check_stack_size("x + " * self.N + "x")
13931406

1407+
# TODO: RUSTPYTHON
1408+
@unittest.expectedFailure
13941409
def test_list(self):
13951410
self.check_stack_size("[" + "x, " * self.N + "x]")
13961411

1412+
# TODO: RUSTPYTHON
1413+
@unittest.expectedFailure
13971414
def test_tuple(self):
13981415
self.check_stack_size("(" + "x, " * self.N + "x)")
13991416

1417+
# TODO: RUSTPYTHON
1418+
@unittest.expectedFailure
14001419
def test_set(self):
14011420
self.check_stack_size("{" + "x, " * self.N + "x}")
14021421

1422+
# TODO: RUSTPYTHON
1423+
@unittest.expectedFailure
14031424
def test_dict(self):
14041425
self.check_stack_size("{" + "x:x, " * self.N + "x:x}")
14051426

1427+
# TODO: RUSTPYTHON
1428+
@unittest.expectedFailure
14061429
def test_func_args(self):
14071430
self.check_stack_size("f(" + "x, " * self.N + ")")
14081431

1432+
# TODO: RUSTPYTHON
1433+
@unittest.expectedFailure
14091434
def test_func_kwargs(self):
14101435
kwargs = (f'a{i}=x' for i in range(self.N))
14111436
self.check_stack_size("f(" + ", ".join(kwargs) + ")")
14121437

1438+
# TODO: RUSTPYTHON
1439+
@unittest.expectedFailure
14131440
def test_meth_args(self):
14141441
self.check_stack_size("o.m(" + "x, " * self.N + ")")
14151442

1443+
# TODO: RUSTPYTHON
1444+
@unittest.expectedFailure
14161445
def test_meth_kwargs(self):
14171446
kwargs = (f'a{i}=x' for i in range(self.N))
14181447
self.check_stack_size("o.m(" + ", ".join(kwargs) + ")")
14191448

1420-
# TODO: RUSTPYTHON
1421-
@unittest.expectedFailure
14221449
def test_func_and(self):
14231450
code = "def f(x):\n"
14241451
code += " x and x\n" * self.N
@@ -1513,6 +1540,8 @@ def test_try_except_as(self):
15131540
"""
15141541
self.check_stack_size(snippet)
15151542

1543+
# TODO: RUSTPYTHON
1544+
@unittest.expectedFailure
15161545
def test_try_except_star_qualified(self):
15171546
snippet = """
15181547
try:
@@ -1524,6 +1553,8 @@ def test_try_except_star_qualified(self):
15241553
"""
15251554
self.check_stack_size(snippet)
15261555

1556+
# TODO: RUSTPYTHON
1557+
@unittest.expectedFailure
15271558
def test_try_except_star_as(self):
15281559
snippet = """
15291560
try:
@@ -1535,6 +1566,8 @@ def test_try_except_star_as(self):
15351566
"""
15361567
self.check_stack_size(snippet)
15371568

1569+
# TODO: RUSTPYTHON
1570+
@unittest.expectedFailure
15381571
def test_try_except_star_finally(self):
15391572
snippet = """
15401573
try:

vm/src/builtins/code.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,18 @@ impl PyCode {
326326
vm.ctx.new_tuple(varnames)
327327
}
328328

329+
#[pygetset]
330+
pub fn co_code(&self, vm: &VirtualMachine) -> crate::builtins::PyBytesRef {
331+
// SAFETY: CodeUnit is #[repr(C)] with size 2, so we can safely transmute to bytes
332+
let bytes = unsafe {
333+
std::slice::from_raw_parts(
334+
self.code.instructions.as_ptr() as *const u8,
335+
self.code.instructions.len() * 2,
336+
)
337+
};
338+
vm.ctx.new_bytes(bytes.to_vec())
339+
}
340+
329341
#[pygetset]
330342
pub fn co_freevars(&self, vm: &VirtualMachine) -> PyTupleRef {
331343
let names = self

0 commit comments

Comments
 (0)