From 50e14ca61945dcb5487e1b54d99fc84c530a32f7 Mon Sep 17 00:00:00 2001
From: Rami Ali <flowergrass@users.noreply.github.com>
Date: Mon, 16 Jan 2017 15:45:55 +1100
Subject: [PATCH] tests/import: Improve builtinimport.c test coverage.

---
 tests/import/import_pkg7.py               | 2 +-
 tests/import/import_pkg8.py               | 2 ++
 tests/import/pkg7/subpkg1/subpkg2/mod3.py | 7 +++++++
 tests/import/pkg8/mod.py                  | 1 +
 4 files changed, 11 insertions(+), 1 deletion(-)
 create mode 100644 tests/import/import_pkg8.py
 create mode 100644 tests/import/pkg8/mod.py

diff --git a/tests/import/import_pkg7.py b/tests/import/import_pkg7.py
index be8564ef6..e1463ebbf 100644
--- a/tests/import/import_pkg7.py
+++ b/tests/import/import_pkg7.py
@@ -1,2 +1,2 @@
-# This tests ... relative imports as used in pkg7
+# This tests ... relative imports as used in pkg7 and imports beyond package root
 import pkg7.subpkg1.subpkg2.mod3
diff --git a/tests/import/import_pkg8.py b/tests/import/import_pkg8.py
new file mode 100644
index 000000000..4c1e832f2
--- /dev/null
+++ b/tests/import/import_pkg8.py
@@ -0,0 +1,2 @@
+# import with no __init__.py files
+import pkg8.mod
diff --git a/tests/import/pkg7/subpkg1/subpkg2/mod3.py b/tests/import/pkg7/subpkg1/subpkg2/mod3.py
index b85b34e60..747cde03b 100644
--- a/tests/import/pkg7/subpkg1/subpkg2/mod3.py
+++ b/tests/import/pkg7/subpkg1/subpkg2/mod3.py
@@ -2,3 +2,10 @@ from ... import mod1
 from ...mod2 import bar
 print(mod1.foo)
 print(bar)
+
+# when attempting relative import beyond top-level package uPy raises ImportError
+# whereas CPython raises a ValueError
+try:
+    from .... import mod1
+except (ImportError, ValueError):
+    print('Error')
diff --git a/tests/import/pkg8/mod.py b/tests/import/pkg8/mod.py
new file mode 100644
index 000000000..b98f02ce6
--- /dev/null
+++ b/tests/import/pkg8/mod.py
@@ -0,0 +1 @@
+print('foo')
-- 
GitLab