Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
N
non-destructive text micropython
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
badge fixer
non-destructive text micropython
Commits
48f43b77
Commit
48f43b77
authored
5 years ago
by
Damien George
Browse files
Options
Downloads
Patches
Plain Diff
tests: Add tests for overriding builtins.__import__.
parent
f60229e2
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
tests/basics/builtin_override.py
+18
-0
18 additions, 0 deletions
tests/basics/builtin_override.py
tests/import/import_override.py
+17
-0
17 additions, 0 deletions
tests/import/import_override.py
with
35 additions
and
0 deletions
tests/basics/builtin_override.py
+
18
−
0
View file @
48f43b77
...
...
@@ -12,7 +12,25 @@ except AttributeError:
print
(
abs
(
1
))
# __build_class__ is handled in a special way
orig_build_class
=
__build_class__
builtins
.
__build_class__
=
lambda
x
,
y
:
(
'
class
'
,
y
)
class
A
:
pass
print
(
A
)
builtins
.
__build_class__
=
orig_build_class
# __import__ is handled in a special way
def
custom_import
(
name
,
globals
,
locals
,
fromlist
,
level
):
print
(
'
import
'
,
name
,
fromlist
,
level
)
class
M
:
a
=
1
b
=
2
return
M
builtins
.
__import__
=
custom_import
__import__
(
'
A
'
,
None
,
None
,
None
,
0
)
import
a
import
a.b
from
a
import
a
from
a.b
import
a
,
b
from
.a
import
a
from
..a
import
a
,
b
This diff is collapsed.
Click to expand it.
tests/import/import_override.py
0 → 100644
+
17
−
0
View file @
48f43b77
# test overriding __import__ combined with importing from the filesystem
def
custom_import
(
name
,
globals
,
locals
,
fromlist
,
level
):
print
(
'
import
'
,
name
,
fromlist
,
level
)
class
M
:
var
=
456
return
M
orig_import
=
__import__
try
:
__import__
(
"
builtins
"
).
__import__
=
custom_import
except
AttributeError
:
print
(
"
SKIP
"
)
raise
SystemExit
# import1a will be done via normal import which will import1b via our custom import
orig_import
(
'
import1a
'
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment