Skip to content

Commit d116e1e

Browse files
committed
tests/class_dict_order: Add tests for class attribute ordering.
1 parent 3d71ca6 commit d116e1e

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

ports/unix/variants/coverage/mpconfigvariant.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
#define MICROPY_WARNINGS_CATEGORY (1)
4545
#undef MICROPY_VFS_ROM_IOCTL
4646
#define MICROPY_VFS_ROM_IOCTL (1)
47+
#define MICROPY_PY_CLASS_ORDERED_LOCALS (1)
4748
#define MICROPY_PY_CRYPTOLIB_CTR (1)
4849
#define MICROPY_SCHEDULER_STATIC_NODES (1)
4950

tests/basics/class_dict_order.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# test __dict__ attribute ordering of a class
2+
3+
if not hasattr(int, "__dict__"):
4+
print("SKIP")
5+
raise SystemExit
6+
7+
from collections import OrderedDict
8+
9+
# dict of a user class
10+
class Foo:
11+
abcd = 1
12+
efgh = 2
13+
ijkl = 3
14+
15+
# dict of a user class
16+
class Foo2:
17+
ijkl = 3
18+
abcd = 1
19+
efgh = 2
20+
21+
print([k for k in Foo.__dict__.keys() if not k.startswith('_')])
22+
print([k for k in Foo2.__dict__.keys() if not k.startswith('_')])
23+
24+
25+
Foo3 = type('Foo3', (object,), OrderedDict(abcd=1, efgh=2, ijkl=3))
26+
print([k for k in Foo3.__dict__.keys() if not k.startswith('_')])

tests/run-tests.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -977,6 +977,7 @@ def run_tests(pyb, tests, args, result_dir, num_threads=1):
977977
skip_tests.add("cmdline/cmd_parsetree.py")
978978
skip_tests.add("cmdline/repl_sys_ps1_ps2.py")
979979
skip_tests.add("extmod/ssl_poll.py")
980+
skip_tests.add("basics/class_dict_order.py")
980981

981982
# Skip thread mutation tests on targets that have unsafe threading behaviour.
982983
if args.thread == "unsafe":

0 commit comments

Comments
 (0)