summaryrefslogtreecommitdiff
path: root/tests/import
diff options
context:
space:
mode:
authorJeff Epler <jeff@adafruit.com>2021-03-15 13:50:49 -0500
committerGitHub <noreply@github.com>2021-03-15 13:50:49 -0500
commit05ed179e11599dd45a76dfb14ecf624d0ff96d68 (patch)
treea046c6d1f117814168150484ed1bf7840d3400d7 /tests/import
parent3cbff45f9aac5ea2855bbc888083d356a91c80fe (diff)
parentf9b4189b4c640823dabb76de8effd2a836da2eb0 (diff)
Merge pull request #4362 from microDev1/code-formatting
Add code formatting and translations check
Diffstat (limited to 'tests/import')
-rw-r--r--tests/import/builtin_import.py8
-rw-r--r--tests/import/gen_context.py2
-rw-r--r--tests/import/import1a.py1
-rw-r--r--tests/import/import1b.py1
-rw-r--r--tests/import/import2a.py2
-rw-r--r--tests/import/import3a.py1
-rw-r--r--tests/import/import_file.py1
-rw-r--r--tests/import/import_pkg1.py1
-rw-r--r--tests/import/import_pkg3.py1
-rw-r--r--tests/import/mpy_invalid.py22
-rw-r--r--tests/import/pkg3/mod2.py1
-rw-r--r--tests/import/pkg6/__init__.py3
-rw-r--r--tests/import/pkg6/x/__init__.py3
-rw-r--r--tests/import/pkg6/x/y.py2
-rw-r--r--tests/import/pkg7/mod1.py4
-rw-r--r--tests/import/pkg7/mod2.py4
-rw-r--r--tests/import/pkg7/subpkg1/subpkg2/mod3.py3
-rw-r--r--tests/import/pkg8/mod.py2
-rw-r--r--tests/import/try_module.py5
19 files changed, 46 insertions, 21 deletions
diff --git a/tests/import/builtin_import.py b/tests/import/builtin_import.py
index 088f631fc..5258da891 100644
--- a/tests/import/builtin_import.py
+++ b/tests/import/builtin_import.py
@@ -1,16 +1,16 @@
# test calling builtin import function
# basic test
-__import__('builtins')
+__import__("builtins")
# first arg should be a string
try:
__import__(1)
except TypeError:
- print('TypeError')
+ print("TypeError")
# level argument should be non-negative
try:
- __import__('xyz', None, None, None, -1)
+ __import__("xyz", None, None, None, -1)
except ValueError:
- print('ValueError')
+ print("ValueError")
diff --git a/tests/import/gen_context.py b/tests/import/gen_context.py
index 02f153146..b7567cf02 100644
--- a/tests/import/gen_context.py
+++ b/tests/import/gen_context.py
@@ -2,8 +2,10 @@ import gen_context2
GLOBAL = "GLOBAL"
+
def gen():
print(GLOBAL)
yield 1
+
gen_context2.call(gen())
diff --git a/tests/import/import1a.py b/tests/import/import1a.py
index 16b2d4d30..9d7d72ff7 100644
--- a/tests/import/import1a.py
+++ b/tests/import/import1a.py
@@ -1,2 +1,3 @@
import import1b
+
print(import1b.var)
diff --git a/tests/import/import1b.py b/tests/import/import1b.py
index be74eca09..8c9d15a71 100644
--- a/tests/import/import1b.py
+++ b/tests/import/import1b.py
@@ -1,4 +1,5 @@
var = 123
+
def throw():
raise ValueError
diff --git a/tests/import/import2a.py b/tests/import/import2a.py
index def6aeb6a..8fb490525 100644
--- a/tests/import/import2a.py
+++ b/tests/import/import2a.py
@@ -1,5 +1,7 @@
from import1b import var
+
print(var)
from import1b import var as var2
+
print(var2)
diff --git a/tests/import/import3a.py b/tests/import/import3a.py
index 2e9d41f71..2fadd8a52 100644
--- a/tests/import/import3a.py
+++ b/tests/import/import3a.py
@@ -1,2 +1,3 @@
from import1b import *
+
print(var)
diff --git a/tests/import/import_file.py b/tests/import/import_file.py
index cb9a88a70..90ec4e41e 100644
--- a/tests/import/import_file.py
+++ b/tests/import/import_file.py
@@ -1,2 +1,3 @@
import import1b
+
print(import1b.__file__)
diff --git a/tests/import/import_pkg1.py b/tests/import/import_pkg1.py
index fe6e4473e..5c1b2ef4c 100644
--- a/tests/import/import_pkg1.py
+++ b/tests/import/import_pkg1.py
@@ -12,5 +12,6 @@ print(pkg_.mod is pkg.mod)
# import using "as"
import pkg.mod as mm
+
print(mm is pkg.mod)
print(mm.foo())
diff --git a/tests/import/import_pkg3.py b/tests/import/import_pkg3.py
index 0ee885b22..ec4697906 100644
--- a/tests/import/import_pkg3.py
+++ b/tests/import/import_pkg3.py
@@ -3,4 +3,5 @@ from pkg import mod
print(mod.foo())
import pkg.mod
+
print(mod is pkg.mod)
diff --git a/tests/import/mpy_invalid.py b/tests/import/mpy_invalid.py
index b9dd99a44..188fb1612 100644
--- a/tests/import/mpy_invalid.py
+++ b/tests/import/mpy_invalid.py
@@ -5,6 +5,7 @@ import sys, uio
try:
uio.IOBase
import uos
+
uos.mount
except (ImportError, AttributeError):
print("SKIP")
@@ -15,8 +16,10 @@ class UserFile(uio.IOBase):
def __init__(self, data):
self.data = data
self.pos = 0
+
def read(self):
return self.data
+
def readinto(self, buf):
n = 0
while n < len(buf) and self.pos < len(self.data):
@@ -24,6 +27,7 @@ class UserFile(uio.IOBase):
n += 1
self.pos += 1
return n
+
def ioctl(self, req, arg):
return 0
@@ -31,37 +35,41 @@ class UserFile(uio.IOBase):
class UserFS:
def __init__(self, files):
self.files = files
+
def mount(self, readonly, mksfs):
pass
+
def umount(self):
pass
+
def stat(self, path):
if path in self.files:
return (32768, 0, 0, 0, 0, 0, 0, 0, 0, 0)
raise OSError
+
def open(self, path, mode):
return UserFile(self.files[path])
# these are the test .mpy files
user_files = {
- '/mod0.mpy': b'', # empty file
- '/mod1.mpy': b'M', # too short header
- '/mod2.mpy': b'M\x00\x00\x00', # bad version
+ "/mod0.mpy": b"", # empty file
+ "/mod1.mpy": b"M", # too short header
+ "/mod2.mpy": b"M\x00\x00\x00", # bad version
}
# create and mount a user filesystem
-uos.mount(UserFS(user_files), '/userfs')
-sys.path.append('/userfs')
+uos.mount(UserFS(user_files), "/userfs")
+sys.path.append("/userfs")
# import .mpy files from the user filesystem
for i in range(len(user_files)):
- mod = 'mod%u' % i
+ mod = "mod%u" % i
try:
__import__(mod)
except Exception as e:
print(mod, type(e).__name__, e)
# unmount and undo path addition
-uos.umount('/userfs')
+uos.umount("/userfs")
sys.path.pop()
diff --git a/tests/import/pkg3/mod2.py b/tests/import/pkg3/mod2.py
index 67f43bad5..37721faaf 100644
--- a/tests/import/pkg3/mod2.py
+++ b/tests/import/pkg3/mod2.py
@@ -1,5 +1,6 @@
print("mod2 __name__:", __name__)
print("in mod2")
+
def foo():
print("mod2.foo()")
diff --git a/tests/import/pkg6/__init__.py b/tests/import/pkg6/__init__.py
index 923531c1b..5215da2ec 100644
--- a/tests/import/pkg6/__init__.py
+++ b/tests/import/pkg6/__init__.py
@@ -1,2 +1,3 @@
from .x import *
-print('init')
+
+print("init")
diff --git a/tests/import/pkg6/x/__init__.py b/tests/import/pkg6/x/__init__.py
index 6b8b84d0e..80817917d 100644
--- a/tests/import/pkg6/x/__init__.py
+++ b/tests/import/pkg6/x/__init__.py
@@ -1,2 +1,3 @@
from .y import *
-print('x')
+
+print("x")
diff --git a/tests/import/pkg6/x/y.py b/tests/import/pkg6/x/y.py
index e8d863c6c..0abc82404 100644
--- a/tests/import/pkg6/x/y.py
+++ b/tests/import/pkg6/x/y.py
@@ -1 +1 @@
-print('y')
+print("y")
diff --git a/tests/import/pkg7/mod1.py b/tests/import/pkg7/mod1.py
index 6b574114d..0a5eb1505 100644
--- a/tests/import/pkg7/mod1.py
+++ b/tests/import/pkg7/mod1.py
@@ -1,2 +1,2 @@
-print('mod1')
-foo = 'mod1.foo'
+print("mod1")
+foo = "mod1.foo"
diff --git a/tests/import/pkg7/mod2.py b/tests/import/pkg7/mod2.py
index 039a5d174..657a6fb52 100644
--- a/tests/import/pkg7/mod2.py
+++ b/tests/import/pkg7/mod2.py
@@ -1,2 +1,2 @@
-print('mod2')
-bar = 'mod2.bar'
+print("mod2")
+bar = "mod2.bar"
diff --git a/tests/import/pkg7/subpkg1/subpkg2/mod3.py b/tests/import/pkg7/subpkg1/subpkg2/mod3.py
index c73e2081f..0aa916d20 100644
--- a/tests/import/pkg7/subpkg1/subpkg2/mod3.py
+++ b/tests/import/pkg7/subpkg1/subpkg2/mod3.py
@@ -1,5 +1,6 @@
from ... import mod1
from ...mod2 import bar
+
print(mod1.foo)
print(bar)
@@ -7,4 +8,4 @@ print(bar)
try:
from .... import mod1
except ValueError:
- print('ValueError')
+ print("ValueError")
diff --git a/tests/import/pkg8/mod.py b/tests/import/pkg8/mod.py
index b98f02ce6..3d3d53a16 100644
--- a/tests/import/pkg8/mod.py
+++ b/tests/import/pkg8/mod.py
@@ -1 +1 @@
-print('foo')
+print("foo")
diff --git a/tests/import/try_module.py b/tests/import/try_module.py
index 03a9db15b..7c97df28b 100644
--- a/tests/import/try_module.py
+++ b/tests/import/try_module.py
@@ -2,8 +2,10 @@
# its namespace stick and namespace of current module not coming back.
import import1b
+
def func1():
- print('func1')
+ print("func1")
+
def func2():
try:
@@ -12,4 +14,5 @@ def func2():
pass
func1()
+
func2()