-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
py/objdict: Disallow possible modifications to fixed dicts.
- Loading branch information
1 parent
5a82ba8
commit a3e01d3
Showing
3 changed files
with
68 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# test that fixed dictionaries cannot be modified | ||
|
||
try: | ||
import uerrno | ||
except ImportError: | ||
print("SKIP") | ||
raise SystemExit | ||
|
||
# Save a copy of uerrno.errorcode, so we can check later | ||
# that it hasn't been modified. | ||
errorcode_copy = uerrno.errorcode.copy() | ||
|
||
try: | ||
uerrno.errorcode.popitem() | ||
except TypeError: | ||
print("TypeError") | ||
|
||
try: | ||
uerrno.errorcode.pop(0) | ||
except TypeError: | ||
print("TypeError") | ||
|
||
try: | ||
uerrno.errorcode.setdefault(0, 0) | ||
except TypeError: | ||
print("TypeError") | ||
|
||
try: | ||
uerrno.errorcode.update([(1, 2)]) | ||
except TypeError: | ||
print("TypeError") | ||
|
||
try: | ||
del uerrno.errorcode[1] | ||
except TypeError: | ||
print("TypeError") | ||
|
||
try: | ||
uerrno.errorcode[1] = 'foo' | ||
except TypeError: | ||
print("TypeError") | ||
|
||
try: | ||
uerrno.errorcode.clear() | ||
except TypeError: | ||
print("TypeError") | ||
|
||
assert uerrno.errorcode == errorcode_copy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
TypeError | ||
TypeError | ||
TypeError | ||
TypeError | ||
TypeError | ||
TypeError | ||
TypeError |