summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorWilliam Deegan <bill@baddogconsulting.com>2021-04-19 02:34:19 (GMT)
committerGitHub <noreply@github.com>2021-04-19 02:34:19 (GMT)
commitca884a6fda9ddc7f11affca8b8cc292e8026eba2 (patch)
tree6aa527c37ba66c7dd4526f06b75ee51d796fa172 /test
parent0b1a9746194554f3578d3f9b7e4d9ad0cd5a0324 (diff)
parent93f8c808e1ffdec5171a60a985e1189e96baaddc (diff)
downloadSCons-ca884a6fda9ddc7f11affca8b8cc292e8026eba2.zip
SCons-ca884a6fda9ddc7f11affca8b8cc292e8026eba2.tar.gz
SCons-ca884a6fda9ddc7f11affca8b8cc292e8026eba2.tar.bz2
Merge pull request #3825 from grossag/topic/grossag/pythondynamicscan
Teach the Python scanner to find generated files and directories
Diffstat (limited to 'test')
-rw-r--r--test/Scanner/Python.py45
-rw-r--r--test/Scanner/Python/SConstruct16
-rw-r--r--test/Scanner/Python/sconstest.skip0
-rw-r--r--test/Scanner/Python/script.py6
-rw-r--r--test/Scanner/Python/to_be_copied/__init__.py1
-rw-r--r--test/Scanner/Python/to_be_copied/helper.py0
-rw-r--r--test/Scanner/Python/to_be_copied/sconstest.skip0
-rw-r--r--test/fixture/python_scanner/from_import_simple_package_module1_func.py1
-rw-r--r--test/fixture/python_scanner/from_nested1_import_multiple.py1
-rw-r--r--test/fixture/python_scanner/imports_unknown_files.py3
-rw-r--r--test/fixture/python_scanner/simple_package/module1.py2
-rw-r--r--test/fixture/python_scanner/simple_package/somefunc.py0
12 files changed, 75 insertions, 0 deletions
diff --git a/test/Scanner/Python.py b/test/Scanner/Python.py
new file mode 100644
index 0000000..b5b3ae5
--- /dev/null
+++ b/test/Scanner/Python.py
@@ -0,0 +1,45 @@
+#!/usr/bin/env python
+#
+# MIT License
+#
+# Copyright The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+"""
+Functional test for the Python scanner. Validates that the scanner is able to
+find dynamically generated dependencies. The SConstruct copies in the
+dependencies and runs a script. The expected behavior is that the scanner
+picks up these dependencies, so SCons understands that the script shouldn't
+be run until the files are copied.
+"""
+
+import TestSCons
+
+test = TestSCons.TestSCons()
+test.dir_fixture('Python')
+test.run(arguments = '.')
+test.pass_test()
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/test/Scanner/Python/SConstruct b/test/Scanner/Python/SConstruct
new file mode 100644
index 0000000..988cf60
--- /dev/null
+++ b/test/Scanner/Python/SConstruct
@@ -0,0 +1,16 @@
+import sys
+
+env = Environment(tools=['python'])
+
+# Copy each file individually instead of copying the dir. This has the benefit
+# of establishing nodes in-memory for each of the resulting files, which helps
+# the scanner work correctly.
+srcDir = env.Dir('to_be_copied')
+for srcNode in srcDir.glob('*'):
+ for destDir in [env.Dir('package1'), env.Dir('package2')]:
+ env.Command(destDir.File(srcNode.name), srcNode,
+ Copy('$TARGET', '$SOURCE'))
+
+# Don't set a dependency on the copy actions on purpose. Scanner should find
+# the dependencies automatically.
+env.Command('a.out', 'script.py', '$PYTHON $SOURCE $TARGET', PYTHON=sys.executable) \ No newline at end of file
diff --git a/test/Scanner/Python/sconstest.skip b/test/Scanner/Python/sconstest.skip
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/test/Scanner/Python/sconstest.skip
diff --git a/test/Scanner/Python/script.py b/test/Scanner/Python/script.py
new file mode 100644
index 0000000..105a575
--- /dev/null
+++ b/test/Scanner/Python/script.py
@@ -0,0 +1,6 @@
+import package1 # noqa: F401
+import package2 # noqa: F401
+import sys
+
+with open(sys.argv[1], 'w') as f:
+ f.write('test')
diff --git a/test/Scanner/Python/to_be_copied/__init__.py b/test/Scanner/Python/to_be_copied/__init__.py
new file mode 100644
index 0000000..3c1c05b
--- /dev/null
+++ b/test/Scanner/Python/to_be_copied/__init__.py
@@ -0,0 +1 @@
+from . import helper # noqa: F401 \ No newline at end of file
diff --git a/test/Scanner/Python/to_be_copied/helper.py b/test/Scanner/Python/to_be_copied/helper.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/test/Scanner/Python/to_be_copied/helper.py
diff --git a/test/Scanner/Python/to_be_copied/sconstest.skip b/test/Scanner/Python/to_be_copied/sconstest.skip
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/test/Scanner/Python/to_be_copied/sconstest.skip
diff --git a/test/fixture/python_scanner/from_import_simple_package_module1_func.py b/test/fixture/python_scanner/from_import_simple_package_module1_func.py
new file mode 100644
index 0000000..e9877fb
--- /dev/null
+++ b/test/fixture/python_scanner/from_import_simple_package_module1_func.py
@@ -0,0 +1 @@
+from simple_package.module1 import somefunc # noqa: F401 \ No newline at end of file
diff --git a/test/fixture/python_scanner/from_nested1_import_multiple.py b/test/fixture/python_scanner/from_nested1_import_multiple.py
new file mode 100644
index 0000000..2cdd47f
--- /dev/null
+++ b/test/fixture/python_scanner/from_nested1_import_multiple.py
@@ -0,0 +1 @@
+from nested1 import module, nested2 # noqa: F401 \ No newline at end of file
diff --git a/test/fixture/python_scanner/imports_unknown_files.py b/test/fixture/python_scanner/imports_unknown_files.py
new file mode 100644
index 0000000..5582e7b
--- /dev/null
+++ b/test/fixture/python_scanner/imports_unknown_files.py
@@ -0,0 +1,3 @@
+import doesntexist # noqa: F401
+import notthere.something # noqa: F401
+from notthere import a, few, things # noqa: F401 \ No newline at end of file
diff --git a/test/fixture/python_scanner/simple_package/module1.py b/test/fixture/python_scanner/simple_package/module1.py
index e69de29..6880c47 100644
--- a/test/fixture/python_scanner/simple_package/module1.py
+++ b/test/fixture/python_scanner/simple_package/module1.py
@@ -0,0 +1,2 @@
+def somefunc():
+ return \ No newline at end of file
diff --git a/test/fixture/python_scanner/simple_package/somefunc.py b/test/fixture/python_scanner/simple_package/somefunc.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/test/fixture/python_scanner/simple_package/somefunc.py