Patchwork [4,of,5] tests: use NO_CHECK_EOF for fragments used to test importing via extension

login
register
mail settings
Submitter Katsunori FUJIWARA
Date Oct. 12, 2018, 7:48 a.m.
Message ID <b1f8e4aa6e384a9a08b3.1539330526@blacknile>
Download mbox | patch
Permalink /patch/35652/
State Accepted
Headers show

Comments

Katsunori FUJIWARA - Oct. 12, 2018, 7:48 a.m.
# HG changeset patch
# User FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
# Date 1538967784 -32400
#      Mon Oct 08 12:03:04 2018 +0900
# Node ID b1f8e4aa6e384a9a08b33d67bcc809eb16dddb38
# Parent  09b2a0aefdbb992918696f6d3685e8276c038c07
# Available At https://bitbucket.org/foozy/mercurial-wip
#              hg pull https://bitbucket.org/foozy/mercurial-wip -r b1f8e4aa6e38
# EXP-Topic tests-fix-import-issues
tests: use NO_CHECK_EOF for fragments used to test importing via extension

test-extension.t is excluded in test-check-module-imports.t, because
import-checker.py reports that some python code fragments in it does
not import modules in recommended style.

These code fragments are used to test importing modules relatively and
absolutely via extension (e.g. issue4029, issue5208, and so on). Test
specific package hierarchy becomes complicated for this purpose, and
it seems reasonable to avoid checking these code fragments with
import-checker.py.

But on the other hand, other code fragments in test-extension.t should
be checked by import-checker.py.

Therefore, this patch uses NO_CHECK_EOF limit mark only for python
code fragments, which are used to test importing via extension in
test-extension.t. NO_CHECK_EOF limit mark tells import-checker.py that
this code fragment should be ignored, via testparseutil.py.

Patch

diff --git a/tests/test-extension.t b/tests/test-extension.t
--- a/tests/test-extension.t
+++ b/tests/test-extension.t
@@ -174,6 +174,13 @@  Check hgweb's load order of extensions a
 
 Check "from __future__ import absolute_import" support for external libraries
 
+(import-checker.py reports issues for some of heredoc python code
+fragments below, because import-checker.py does not know test specific
+package hierarchy. NO_CHECK_* should be used as a limit mark of
+heredoc, in order to make import-checker.py ignore them. For
+simplicity, all python code fragments below are generated with such
+limit mark, regardless of importing module or not.)
+
 #if windows
   $ PATHSEP=";"
 #else
@@ -187,30 +194,30 @@  Check "from __future__ import absolute_i
   $ touch $TESTTMP/libroot/mod/__init__.py
   $ echo "s = 'libroot/mod/ambig.py'" > $TESTTMP/libroot/mod/ambig.py
 
-  $ cat > $TESTTMP/libroot/mod/ambigabs.py <<EOF
+  $ cat > $TESTTMP/libroot/mod/ambigabs.py <<NO_CHECK_EOF
   > from __future__ import absolute_import
   > import ambig # should load "libroot/ambig.py"
   > s = ambig.s
-  > EOF
-  $ cat > loadabs.py <<EOF
+  > NO_CHECK_EOF
+  $ cat > loadabs.py <<NO_CHECK_EOF
   > import mod.ambigabs as ambigabs
   > def extsetup():
   >     print('ambigabs.s=%s' % ambigabs.s)
-  > EOF
+  > NO_CHECK_EOF
   $ (PYTHONPATH=${PYTHONPATH}${PATHSEP}${TESTTMP}/libroot; hg --config extensions.loadabs=loadabs.py root)
   ambigabs.s=libroot/ambig.py
   $TESTTMP/a
 
 #if no-py3k
-  $ cat > $TESTTMP/libroot/mod/ambigrel.py <<EOF
+  $ cat > $TESTTMP/libroot/mod/ambigrel.py <<NO_CHECK_EOF
   > import ambig # should load "libroot/mod/ambig.py"
   > s = ambig.s
-  > EOF
-  $ cat > loadrel.py <<EOF
+  > NO_CHECK_EOF
+  $ cat > loadrel.py <<NO_CHECK_EOF
   > import mod.ambigrel as ambigrel
   > def extsetup():
   >     print('ambigrel.s=%s' % ambigrel.s)
-  > EOF
+  > NO_CHECK_EOF
   $ (PYTHONPATH=${PYTHONPATH}${PATHSEP}${TESTTMP}/libroot; hg --config extensions.loadrel=loadrel.py root)
   ambigrel.s=libroot/mod/ambig.py
   $TESTTMP/a
@@ -219,25 +226,25 @@  Check "from __future__ import absolute_i
 Check absolute/relative import of extension specific modules
 
   $ mkdir $TESTTMP/extroot
-  $ cat > $TESTTMP/extroot/bar.py <<EOF
+  $ cat > $TESTTMP/extroot/bar.py <<NO_CHECK_EOF
   > s = 'this is extroot.bar'
-  > EOF
+  > NO_CHECK_EOF
   $ mkdir $TESTTMP/extroot/sub1
-  $ cat > $TESTTMP/extroot/sub1/__init__.py <<EOF
+  $ cat > $TESTTMP/extroot/sub1/__init__.py <<NO_CHECK_EOF
   > s = 'this is extroot.sub1.__init__'
-  > EOF
-  $ cat > $TESTTMP/extroot/sub1/baz.py <<EOF
+  > NO_CHECK_EOF
+  $ cat > $TESTTMP/extroot/sub1/baz.py <<NO_CHECK_EOF
   > s = 'this is extroot.sub1.baz'
-  > EOF
-  $ cat > $TESTTMP/extroot/__init__.py <<EOF
+  > NO_CHECK_EOF
+  $ cat > $TESTTMP/extroot/__init__.py <<NO_CHECK_EOF
   > s = 'this is extroot.__init__'
   > import foo
   > def extsetup(ui):
   >     ui.write('(extroot) ', foo.func(), '\n')
   >     ui.flush()
-  > EOF
-
-  $ cat > $TESTTMP/extroot/foo.py <<EOF
+  > NO_CHECK_EOF
+
+  $ cat > $TESTTMP/extroot/foo.py <<NO_CHECK_EOF
   > # test absolute import
   > buf = []
   > def func():
@@ -257,7 +264,7 @@  Check absolute/relative import of extens
   > # NOT "not fromlist" and NOT "level != -1" case
   > from extroot.bar import s
   > buf.append('from extroot.bar import s: %s' % s)
-  > EOF
+  > NO_CHECK_EOF
   $ (PYTHONPATH=${PYTHONPATH}${PATHSEP}${TESTTMP}; hg --config extensions.extroot=$TESTTMP/extroot root)
   (extroot) from extroot.bar import *: this is extroot.bar
   (extroot) import extroot.sub1.baz: this is extroot.sub1.baz
@@ -269,7 +276,7 @@  Check absolute/relative import of extens
 #if no-py3k
   $ rm "$TESTTMP"/extroot/foo.*
   $ rm -Rf "$TESTTMP/extroot/__pycache__"
-  $ cat > $TESTTMP/extroot/foo.py <<EOF
+  $ cat > $TESTTMP/extroot/foo.py <<NO_CHECK_EOF
   > # test relative import
   > buf = []
   > def func():
@@ -289,7 +296,7 @@  Check absolute/relative import of extens
   > # NOT "not fromlist" and NOT "level != -1" case
   > from bar import s
   > buf.append('from bar import s: %s' % s)
-  > EOF
+  > NO_CHECK_EOF
   $ hg --config extensions.extroot=$TESTTMP/extroot root
   (extroot) from bar import *: this is extroot.bar
   (extroot) import sub1.baz: this is extroot.sub1.baz
@@ -321,16 +328,16 @@  feature.
   $ touch $TESTTMP/extlibroot/lsub1/__init__.py
   $ touch $TESTTMP/extlibroot/lsub1/lsub2/__init__.py
 
-  $ cat > $TESTTMP/extlibroot/lsub1/lsub2/called.py <<EOF
+  $ cat > $TESTTMP/extlibroot/lsub1/lsub2/called.py <<NO_CHECK_EOF
   > def func():
   >     return b"this is extlibroot.lsub1.lsub2.called.func()"
-  > EOF
-  $ cat > $TESTTMP/extlibroot/lsub1/lsub2/unused.py <<EOF
+  > NO_CHECK_EOF
+  $ cat > $TESTTMP/extlibroot/lsub1/lsub2/unused.py <<NO_CHECK_EOF
   > raise Exception("extlibroot.lsub1.lsub2.unused is loaded unintentionally")
-  > EOF
-  $ cat > $TESTTMP/extlibroot/lsub1/lsub2/used.py <<EOF
+  > NO_CHECK_EOF
+  $ cat > $TESTTMP/extlibroot/lsub1/lsub2/used.py <<NO_CHECK_EOF
   > detail = b"this is extlibroot.lsub1.lsub2.used"
-  > EOF
+  > NO_CHECK_EOF
 
 Setup sub-package of "external library", which causes instantiation of
 demandmod in "recurse down the module chain" code path. Relative
@@ -338,45 +345,45 @@  importing with "absolute_import" feature
 >=1 " doesn't cause instantiation of demandmod.
 
   $ mkdir -p $TESTTMP/extlibroot/recursedown/abs
-  $ cat > $TESTTMP/extlibroot/recursedown/abs/used.py <<EOF
+  $ cat > $TESTTMP/extlibroot/recursedown/abs/used.py <<NO_CHECK_EOF
   > detail = b"this is extlibroot.recursedown.abs.used"
-  > EOF
-  $ cat > $TESTTMP/extlibroot/recursedown/abs/__init__.py <<EOF
+  > NO_CHECK_EOF
+  $ cat > $TESTTMP/extlibroot/recursedown/abs/__init__.py <<NO_CHECK_EOF
   > from __future__ import absolute_import
   > from extlibroot.recursedown.abs.used import detail
-  > EOF
+  > NO_CHECK_EOF
 
   $ mkdir -p $TESTTMP/extlibroot/recursedown/legacy
-  $ cat > $TESTTMP/extlibroot/recursedown/legacy/used.py <<EOF
+  $ cat > $TESTTMP/extlibroot/recursedown/legacy/used.py <<NO_CHECK_EOF
   > detail = b"this is extlibroot.recursedown.legacy.used"
-  > EOF
-  $ cat > $TESTTMP/extlibroot/recursedown/legacy/__init__.py <<EOF
+  > NO_CHECK_EOF
+  $ cat > $TESTTMP/extlibroot/recursedown/legacy/__init__.py <<NO_CHECK_EOF
   > # legacy style (level == -1) import
   > from extlibroot.recursedown.legacy.used import detail
-  > EOF
-
-  $ cat > $TESTTMP/extlibroot/recursedown/__init__.py <<EOF
+  > NO_CHECK_EOF
+
+  $ cat > $TESTTMP/extlibroot/recursedown/__init__.py <<NO_CHECK_EOF
   > from __future__ import absolute_import
   > from extlibroot.recursedown.abs import detail as absdetail
   > from .legacy import detail as legacydetail
-  > EOF
+  > NO_CHECK_EOF
 
 Setup package that re-exports an attribute of its submodule as the same
 name. This leaves 'shadowing.used' pointing to 'used.detail', but still
 the submodule 'used' should be somehow accessible. (issue5617)
 
   $ mkdir -p $TESTTMP/extlibroot/shadowing
-  $ cat > $TESTTMP/extlibroot/shadowing/used.py <<EOF
+  $ cat > $TESTTMP/extlibroot/shadowing/used.py <<NO_CHECK_EOF
   > detail = b"this is extlibroot.shadowing.used"
-  > EOF
-  $ cat > $TESTTMP/extlibroot/shadowing/proxied.py <<EOF
+  > NO_CHECK_EOF
+  $ cat > $TESTTMP/extlibroot/shadowing/proxied.py <<NO_CHECK_EOF
   > from __future__ import absolute_import
   > from extlibroot.shadowing.used import detail
-  > EOF
-  $ cat > $TESTTMP/extlibroot/shadowing/__init__.py <<EOF
+  > NO_CHECK_EOF
+  $ cat > $TESTTMP/extlibroot/shadowing/__init__.py <<NO_CHECK_EOF
   > from __future__ import absolute_import
   > from .used import detail as used
-  > EOF
+  > NO_CHECK_EOF
 
 Setup extension local modules to be imported with "absolute_import"
 feature.
@@ -385,33 +392,33 @@  feature.
   $ touch $TESTTMP/absextroot/xsub1/__init__.py
   $ touch $TESTTMP/absextroot/xsub1/xsub2/__init__.py
 
-  $ cat > $TESTTMP/absextroot/xsub1/xsub2/called.py <<EOF
+  $ cat > $TESTTMP/absextroot/xsub1/xsub2/called.py <<NO_CHECK_EOF
   > def func():
   >     return b"this is absextroot.xsub1.xsub2.called.func()"
-  > EOF
-  $ cat > $TESTTMP/absextroot/xsub1/xsub2/unused.py <<EOF
+  > NO_CHECK_EOF
+  $ cat > $TESTTMP/absextroot/xsub1/xsub2/unused.py <<NO_CHECK_EOF
   > raise Exception("absextroot.xsub1.xsub2.unused is loaded unintentionally")
-  > EOF
-  $ cat > $TESTTMP/absextroot/xsub1/xsub2/used.py <<EOF
+  > NO_CHECK_EOF
+  $ cat > $TESTTMP/absextroot/xsub1/xsub2/used.py <<NO_CHECK_EOF
   > detail = b"this is absextroot.xsub1.xsub2.used"
-  > EOF
+  > NO_CHECK_EOF
 
 Setup extension local modules to examine whether demand importing
 works as expected in "level > 1" case.
 
-  $ cat > $TESTTMP/absextroot/relimportee.py <<EOF
+  $ cat > $TESTTMP/absextroot/relimportee.py <<NO_CHECK_EOF
   > detail = b"this is absextroot.relimportee"
-  > EOF
-  $ cat > $TESTTMP/absextroot/xsub1/xsub2/relimporter.py <<EOF
+  > NO_CHECK_EOF
+  $ cat > $TESTTMP/absextroot/xsub1/xsub2/relimporter.py <<NO_CHECK_EOF
   > from __future__ import absolute_import
   > from ... import relimportee
   > detail = b"this relimporter imports %r" % (relimportee.detail)
-  > EOF
+  > NO_CHECK_EOF
 
 Setup modules, which actually import extension local modules at
 runtime.
 
-  $ cat > $TESTTMP/absextroot/absolute.py << EOF
+  $ cat > $TESTTMP/absextroot/absolute.py << NO_CHECK_EOF
   > from __future__ import absolute_import
   > 
   > # import extension local modules absolutely (level = 0)
@@ -423,9 +430,9 @@  runtime.
   >     result.append(used.detail)
   >     result.append(func())
   >     return result
-  > EOF
-
-  $ cat > $TESTTMP/absextroot/relative.py << EOF
+  > NO_CHECK_EOF
+
+  $ cat > $TESTTMP/absextroot/relative.py << NO_CHECK_EOF
   > from __future__ import absolute_import
   > 
   > # import extension local modules relatively (level == 1)
@@ -441,11 +448,11 @@  runtime.
   >     result.append(func())
   >     result.append(relimporter.detail)
   >     return result
-  > EOF
+  > NO_CHECK_EOF
 
 Setup main procedure of extension.
 
-  $ cat > $TESTTMP/absextroot/__init__.py <<EOF
+  $ cat > $TESTTMP/absextroot/__init__.py <<NO_CHECK_EOF
   > from __future__ import absolute_import
   > from mercurial import registrar
   > cmdtable = {}
@@ -480,7 +487,7 @@  Setup main procedure of extension.
   >     result.append(legacydetail)
   >     result.append(proxied.detail)
   >     ui.write(b'LIB: %s\n' % '\nLIB: '.join(result))
-  > EOF
+  > NO_CHECK_EOF
 
 Examine module importing.
 
@@ -510,11 +517,11 @@  See also issue5208 for detail about exam
   $ f -q $TESTTMP/extlibroot/lsub1/lsub2/notexist.py
   $TESTTMP/extlibroot/lsub1/lsub2/notexist.py: file not found
 
-  $ cat > $TESTTMP/notexist.py <<EOF
+  $ cat > $TESTTMP/notexist.py <<NO_CHECK_EOF
   > text = 'notexist.py at root is loaded unintentionally\n'
-  > EOF
-
-  $ cat > $TESTTMP/checkrelativity.py <<EOF
+  > NO_CHECK_EOF
+
+  $ cat > $TESTTMP/checkrelativity.py <<NO_CHECK_EOF
   > from mercurial import registrar
   > cmdtable = {}
   > command = registrar.command(cmdtable)
@@ -529,12 +536,16 @@  See also issue5208 for detail about exam
   >         return 1 # unintentional success
   >     except ImportError:
   >         pass # intentional failure
-  > EOF
+  > NO_CHECK_EOF
 
   $ (PYTHONPATH=${PYTHONPATH}${PATHSEP}${TESTTMP}; hg --config extensions.checkrelativity=$TESTTMP/checkrelativity.py checkrelativity)
 
 #endif
 
+(Here, module importing tests are finished. Therefore, use other than
+NO_CHECK_* limit mark for heredoc python files, in order to apply
+import-checker.py or so on their contents)
+
 Make sure a broken uisetup doesn't globally break hg:
   $ cat > $TESTTMP/baduisetup.py <<EOF
   > def uisetup(ui):