diff options
Diffstat (limited to 'python')
| -rw-r--r-- | python/Android.bp | 24 | ||||
| -rw-r--r-- | python/androidmk.go | 22 | ||||
| -rw-r--r-- | python/binary.go | 5 | ||||
| -rw-r--r-- | python/installer.go | 6 | ||||
| -rw-r--r-- | python/proto.go | 2 | ||||
| -rw-r--r-- | python/python.go | 43 | ||||
| -rw-r--r-- | python/python_test.go | 61 | ||||
| -rw-r--r-- | python/test.go | 7 | ||||
| -rw-r--r-- | python/tests/Android.bp | 16 | ||||
| -rw-r--r-- | python/tests/par_test.py | 7 | ||||
| -rw-r--r-- | python/tests/py-cmd_test.py | 78 | ||||
| -rwxr-xr-x | python/tests/runtest.sh | 26 | ||||
| -rw-r--r-- | python/tests/testpkg/__init__.py | 0 | ||||
| -rw-r--r-- | python/tests/testpkg/par_test.py | 8 | ||||
| -rw-r--r-- | python/tests/testpkg/pycmd_test.py | 33 |
15 files changed, 274 insertions, 64 deletions
diff --git a/python/Android.bp b/python/Android.bp new file mode 100644 index 000000000..ffd03fe89 --- /dev/null +++ b/python/Android.bp @@ -0,0 +1,24 @@ +bootstrap_go_package { + name: "soong-python", + pkgPath: "android/soong/python", + deps: [ + "blueprint", + "soong-android", + "soong-tradefed", + ], + srcs: [ + "androidmk.go", + "binary.go", + "builder.go", + "defaults.go", + "installer.go", + "library.go", + "proto.go", + "python.go", + "test.go", + ], + testSrcs: [ + "python_test.go", + ], + pluginFor: ["soong_build"], +} diff --git a/python/androidmk.go b/python/androidmk.go index 1e51e7b8a..247b80dc0 100644 --- a/python/androidmk.go +++ b/python/androidmk.go @@ -66,15 +66,13 @@ func (p *testDecorator) AndroidMk(base *Module, ret *android.AndroidMkData) { fmt.Fprintln(w, "LOCAL_COMPATIBILITY_SUITE :=", strings.Join(p.binaryDecorator.binaryProperties.Test_suites, " ")) } - // If the test config has an explicit config specified use it. - if p.testProperties.Test_config != nil { - fmt.Fprintln(w, "LOCAL_TEST_CONFIG :=", - *p.testProperties.Test_config) - } else { - if p.testConfig != nil { - fmt.Fprintln(w, "LOCAL_FULL_TEST_CONFIG :=", - p.testConfig.String()) - } + if p.testConfig != nil { + fmt.Fprintln(w, "LOCAL_FULL_TEST_CONFIG :=", + p.testConfig.String()) + } + + if !BoolDefault(p.binaryProperties.Auto_gen_config, true) { + fmt.Fprintln(w, "LOCAL_DISABLE_AUTO_GENERATE_TEST_CONFIG := true") } }) base.subAndroidMk(ret, p.binaryDecorator.pythonInstaller) @@ -89,13 +87,13 @@ func (installer *pythonInstaller) AndroidMk(base *Module, ret *android.AndroidMk ret.Required = append(ret.Required, "libc++") ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) { - path := installer.path.RelPathString() - dir, file := filepath.Split(path) + path, file := filepath.Split(installer.path.ToMakePath().String()) stem := strings.TrimSuffix(file, filepath.Ext(file)) fmt.Fprintln(w, "LOCAL_MODULE_SUFFIX := "+filepath.Ext(file)) - fmt.Fprintln(w, "LOCAL_MODULE_PATH := $(OUT_DIR)/"+filepath.Clean(dir)) + fmt.Fprintln(w, "LOCAL_MODULE_PATH := "+path) fmt.Fprintln(w, "LOCAL_MODULE_STEM := "+stem) fmt.Fprintln(w, "LOCAL_SHARED_LIBRARIES := "+strings.Join(installer.androidMkSharedLibs, " ")) + fmt.Fprintln(w, "LOCAL_CHECK_ELF_FILES := false") }) } diff --git a/python/binary.go b/python/binary.go index 140f07af9..695fa123b 100644 --- a/python/binary.go +++ b/python/binary.go @@ -47,6 +47,11 @@ type BinaryProperties struct { // false it will act much like the normal `python` executable, but with the sources and // libraries automatically included in the PYTHONPATH. Autorun *bool `android:"arch_variant"` + + // Flag to indicate whether or not to create test config automatically. If AndroidTest.xml + // doesn't exist next to the Android.bp, this attribute doesn't need to be set to true + // explicitly. + Auto_gen_config *bool } type binaryDecorator struct { diff --git a/python/installer.go b/python/installer.go index 62f36f4b5..396f03667 100644 --- a/python/installer.go +++ b/python/installer.go @@ -33,7 +33,7 @@ type pythonInstaller struct { dir64 string relative string - path android.OutputPath + path android.InstallPath androidMkSharedLibs []string } @@ -47,12 +47,12 @@ func NewPythonInstaller(dir, dir64 string) *pythonInstaller { var _ installer = (*pythonInstaller)(nil) -func (installer *pythonInstaller) installDir(ctx android.ModuleContext) android.OutputPath { +func (installer *pythonInstaller) installDir(ctx android.ModuleContext) android.InstallPath { dir := installer.dir if ctx.Arch().ArchType.Multilib == "lib64" && installer.dir64 != "" { dir = installer.dir64 } - if !ctx.Host() && !ctx.Arch().Native { + if !ctx.Host() && ctx.Config().HasMultilibConflict(ctx.Arch().ArchType) { dir = filepath.Join(dir, ctx.Arch().ArchType.String()) } return android.PathForModuleInstall(ctx, dir, installer.relative) diff --git a/python/proto.go b/python/proto.go index 85ed1a517..b71e047a5 100644 --- a/python/proto.go +++ b/python/proto.go @@ -34,7 +34,7 @@ func genProto(ctx android.ModuleContext, protoFile android.Path, flags android.P // Proto generated python files have an unknown package name in the path, so package the entire output directory // into a srcszip. zipCmd := rule.Command(). - Tool(ctx.Config().HostToolPath(ctx, "soong_zip")). + BuiltTool(ctx, "soong_zip"). FlagWithOutput("-o ", srcsZipFile) if pkgPath != "" { zipCmd.FlagWithArg("-P ", pkgPath) diff --git a/python/python.go b/python/python.go index ad089090b..8b912be17 100644 --- a/python/python.go +++ b/python/python.go @@ -306,22 +306,17 @@ func (p *Module) DepsMutator(ctx android.BottomUpMutatorContext) { if p.bootstrapper.autorun() { launcherModule = "py2-launcher-autorun" } - ctx.AddFarVariationDependencies([]blueprint.Variation{ - {Mutator: "arch", Variation: ctx.Target().String()}, - }, launcherTag, launcherModule) + ctx.AddFarVariationDependencies(ctx.Target().Variations(), launcherTag, launcherModule) // Add py2-launcher shared lib dependencies. Ideally, these should be // derived from the `shared_libs` property of "py2-launcher". However, we // cannot read the property at this stage and it will be too late to add // dependencies later. - ctx.AddFarVariationDependencies([]blueprint.Variation{ - {Mutator: "arch", Variation: ctx.Target().String()}, - }, launcherSharedLibTag, "libsqlite") + ctx.AddFarVariationDependencies(ctx.Target().Variations(), launcherSharedLibTag, "libsqlite") if ctx.Target().Os.Bionic() { - ctx.AddFarVariationDependencies([]blueprint.Variation{ - {Mutator: "arch", Variation: ctx.Target().String()}, - }, launcherSharedLibTag, "libc", "libdl", "libm") + ctx.AddFarVariationDependencies(ctx.Target().Variations(), launcherSharedLibTag, + "libc", "libdl", "libm") } } @@ -331,9 +326,29 @@ func (p *Module) DepsMutator(ctx android.BottomUpMutatorContext) { p.properties.Version.Py3.Libs)...) if p.bootstrapper != nil && p.isEmbeddedLauncherEnabled(pyVersion3) { - //TODO(nanzhang): Add embedded launcher for Python3. - ctx.PropertyErrorf("version.py3.embedded_launcher", - "is not supported yet for Python3.") + ctx.AddVariationDependencies(nil, pythonLibTag, "py3-stdlib") + + launcherModule := "py3-launcher" + if p.bootstrapper.autorun() { + launcherModule = "py3-launcher-autorun" + } + ctx.AddFarVariationDependencies(ctx.Target().Variations(), launcherTag, launcherModule) + + // Add py3-launcher shared lib dependencies. Ideally, these should be + // derived from the `shared_libs` property of "py3-launcher". However, we + // cannot read the property at this stage and it will be too late to add + // dependencies later. + ctx.AddFarVariationDependencies(ctx.Target().Variations(), launcherSharedLibTag, "libsqlite") + + if ctx.Device() { + ctx.AddFarVariationDependencies(ctx.Target().Variations(), launcherSharedLibTag, + "liblog") + } + + if ctx.Target().Os.Bionic() { + ctx.AddFarVariationDependencies(ctx.Target().Variations(), launcherSharedLibTag, + "libc", "libdl", "libm") + } } default: panic(fmt.Errorf("unknown Python Actual_version: %q for module: %q.", @@ -375,11 +390,11 @@ func (p *Module) GenerateAndroidBuildActions(ctx android.ModuleContext) { // Only Python binaries and test has non-empty bootstrapper. if p.bootstrapper != nil { p.walkTransitiveDeps(ctx) - // TODO(nanzhang): Since embedded launcher is not supported for Python3 for now, - // so we initialize "embedded_launcher" to false. embeddedLauncher := false if p.properties.Actual_version == pyVersion2 { embeddedLauncher = p.isEmbeddedLauncherEnabled(pyVersion2) + } else { + embeddedLauncher = p.isEmbeddedLauncherEnabled(pyVersion3) } p.installSource = p.bootstrapper.bootstrap(ctx, p.properties.Actual_version, embeddedLauncher, p.srcsPathMappings, p.srcsZip, p.depsSrcsZips) diff --git a/python/python_test.go b/python/python_test.go index e5fe126c1..1245ca184 100644 --- a/python/python_test.go +++ b/python/python_test.go @@ -28,6 +28,8 @@ import ( "android/soong/android" ) +var buildDir string + type pyModule struct { name string actualVersion string @@ -50,7 +52,7 @@ var ( noSrcFileErr = moduleVariantErrTemplate + "doesn't have any source files!" badSrcFileExtErr = moduleVariantErrTemplate + "srcs: found non (.py|.proto) file: %q!" badDataFileExtErr = moduleVariantErrTemplate + "data: found (.py|.proto) file: %q!" - bpFile = "Blueprints" + bpFile = "Android.bp" data = []struct { desc string @@ -71,7 +73,7 @@ var ( }, errors: []string{ fmt.Sprintf(noSrcFileErr, - "dir/Blueprints:1:1", "lib1", "PY3"), + "dir/Android.bp:1:1", "lib1", "PY3"), }, }, { @@ -90,7 +92,7 @@ var ( }, errors: []string{ fmt.Sprintf(badSrcFileExtErr, - "dir/Blueprints:3:11", "lib1", "PY3", "dir/file1.exe"), + "dir/Android.bp:3:11", "lib1", "PY3", "dir/file1.exe"), }, }, { @@ -113,7 +115,7 @@ var ( }, errors: []string{ fmt.Sprintf(badDataFileExtErr, - "dir/Blueprints:6:11", "lib1", "PY3", "dir/file2.py"), + "dir/Android.bp:6:11", "lib1", "PY3", "dir/file2.py"), }, }, { @@ -149,9 +151,9 @@ var ( }, errors: []string{ fmt.Sprintf(pkgPathErrTemplate, - "dir/Blueprints:11:15", "lib2", "PY3", "a/c/../../../"), + "dir/Android.bp:11:15", "lib2", "PY3", "a/c/../../../"), fmt.Sprintf(pkgPathErrTemplate, - "dir/Blueprints:19:15", "lib3", "PY3", "/a/c/../../"), + "dir/Android.bp:19:15", "lib3", "PY3", "/a/c/../../"), }, }, { @@ -174,11 +176,11 @@ var ( "dir/-e/f/file1.py": nil, }, errors: []string{ - fmt.Sprintf(badIdentifierErrTemplate, "dir/Blueprints:4:11", + fmt.Sprintf(badIdentifierErrTemplate, "dir/Android.bp:4:11", "lib1", "PY3", "a/b/c/-e/f/file1.py", "-e"), - fmt.Sprintf(badIdentifierErrTemplate, "dir/Blueprints:4:11", + fmt.Sprintf(badIdentifierErrTemplate, "dir/Android.bp:4:11", "lib1", "PY3", "a/b/c/.file1.py", ".file1"), - fmt.Sprintf(badIdentifierErrTemplate, "dir/Blueprints:4:11", + fmt.Sprintf(badIdentifierErrTemplate, "dir/Android.bp:4:11", "lib1", "PY3", "a/b/c/123/file1.py", "123"), }, }, @@ -211,7 +213,7 @@ var ( "dir/file1.py": nil, }, errors: []string{ - fmt.Sprintf(dupRunfileErrTemplate, "dir/Blueprints:9:6", + fmt.Sprintf(dupRunfileErrTemplate, "dir/Android.bp:9:6", "lib2", "PY3", "a/b/c/file1.py", "lib2", "dir/file1.py", "lib1", "dir/c/file1.py"), }, @@ -324,23 +326,18 @@ var ( ) func TestPythonModule(t *testing.T) { - config, buildDir := setupBuildEnv(t) - defer tearDownBuildEnv(buildDir) for _, d := range data { t.Run(d.desc, func(t *testing.T) { + config := android.TestConfig(buildDir, nil, "", d.mockFiles) ctx := android.NewTestContext() ctx.PreDepsMutators(func(ctx android.RegisterMutatorsContext) { ctx.BottomUp("version_split", versionSplitMutator()).Parallel() }) - ctx.RegisterModuleType("python_library_host", - android.ModuleFactoryAdaptor(PythonLibraryHostFactory)) - ctx.RegisterModuleType("python_binary_host", - android.ModuleFactoryAdaptor(PythonBinaryHostFactory)) - ctx.RegisterModuleType("python_defaults", - android.ModuleFactoryAdaptor(defaultsFactory)) + ctx.RegisterModuleType("python_library_host", PythonLibraryHostFactory) + ctx.RegisterModuleType("python_binary_host", PythonBinaryHostFactory) + ctx.RegisterModuleType("python_defaults", defaultsFactory) ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators) - ctx.Register() - ctx.MockFileSystem(d.mockFiles) + ctx.Register(config) _, testErrs := ctx.ParseBlueprintsFiles(bpFile) android.FailIfErrored(t, testErrs) _, actErrs := ctx.PrepareBuildActions(config) @@ -428,17 +425,25 @@ func expectModule(t *testing.T, ctx *android.TestContext, buildDir, name, varian return } -func setupBuildEnv(t *testing.T) (config android.Config, buildDir string) { - buildDir, err := ioutil.TempDir("", buildNamePrefix) +func setUp() { + var err error + buildDir, err = ioutil.TempDir("", "soong_python_test") if err != nil { - t.Fatal(err) + panic(err) } - - config = android.TestConfig(buildDir, nil) - - return } -func tearDownBuildEnv(buildDir string) { +func tearDown() { os.RemoveAll(buildDir) } + +func TestMain(m *testing.M) { + run := func() int { + setUp() + defer tearDown() + + return m.Run() + } + + os.Exit(run()) +} diff --git a/python/test.go b/python/test.go index 55b0ab53a..a669c73a6 100644 --- a/python/test.go +++ b/python/test.go @@ -29,11 +29,11 @@ func init() { type TestProperties struct { // the name of the test configuration (for example "AndroidTest.xml") that should be // installed with the module. - Test_config *string `android:"arch_variant"` + Test_config *string `android:"path,arch_variant"` // the name of the test configuration template (for example "AndroidTestTemplate.xml") that // should be installed with the module. - Test_config_template *string `android:"arch_variant"` + Test_config_template *string `android:"path,arch_variant"` } type testDecorator struct { @@ -50,7 +50,8 @@ func (test *testDecorator) bootstrapperProps() []interface{} { func (test *testDecorator) install(ctx android.ModuleContext, file android.Path) { test.testConfig = tradefed.AutoGenPythonBinaryHostTestConfig(ctx, test.testProperties.Test_config, - test.testProperties.Test_config_template, test.binaryDecorator.binaryProperties.Test_suites) + test.testProperties.Test_config_template, test.binaryDecorator.binaryProperties.Test_suites, + test.binaryDecorator.binaryProperties.Auto_gen_config) test.binaryDecorator.pythonInstaller.dir = "nativetest" test.binaryDecorator.pythonInstaller.dir64 = "nativetest64" diff --git a/python/tests/Android.bp b/python/tests/Android.bp index 1f4305c41..c8bf42023 100644 --- a/python/tests/Android.bp +++ b/python/tests/Android.bp @@ -27,6 +27,22 @@ python_test_host { }, py3: { enabled: false, + embedded_launcher: true, + }, + }, +} + +python_test_host { + name: "par_test3", + main: "par_test.py", + srcs: [ + "par_test.py", + "testpkg/par_test.py", + ], + + version: { + py3: { + embedded_launcher: true, }, }, } diff --git a/python/tests/par_test.py b/python/tests/par_test.py index 1fafe0f82..56a5063c4 100644 --- a/python/tests/par_test.py +++ b/python/tests/par_test.py @@ -44,6 +44,13 @@ assert_equal("sys.path[0]", sys.path[0], archive) assert_equal("sys.path[1]", sys.path[1], os.path.join(archive, "internal")) assert_equal("sys.path[2]", sys.path[2], os.path.join(archive, "internal", "stdlib")) +if os.getenv('ARGTEST', False): + assert_equal("len(sys.argv)", len(sys.argv), 3) + assert_equal("sys.argv[1]", sys.argv[1], "--arg1") + assert_equal("sys.argv[2]", sys.argv[2], "arg2") +else: + assert_equal("len(sys.argv)", len(sys.argv), 1) + if failed: sys.exit(1) diff --git a/python/tests/py-cmd_test.py b/python/tests/py-cmd_test.py new file mode 100644 index 000000000..acda2d742 --- /dev/null +++ b/python/tests/py-cmd_test.py @@ -0,0 +1,78 @@ +# Copyright 2020 Google Inc. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +import site +import sys + +# This file checks the visible python state against expected values when run +# using a prebuilt python. + +failed = False +def assert_equal(what, a, b): + global failed + if a != b: + print("Expected %s('%s') == '%s'" % (what, a, b)) + failed = True + +assert_equal("__name__", __name__, "__main__") +assert_equal("os.path.basename(__file__)", os.path.basename(__file__), "py-cmd_test.py") + +if os.getenv('ARGTEST', False): + assert_equal("len(sys.argv)", len(sys.argv), 3) + assert_equal("sys.argv[1]", sys.argv[1], "arg1") + assert_equal("sys.argv[2]", sys.argv[2], "arg2") +elif os.getenv('ARGTEST2', False): + assert_equal("len(sys.argv)", len(sys.argv), 3) + assert_equal("sys.argv[1]", sys.argv[1], "--arg1") + assert_equal("sys.argv[2]", sys.argv[2], "arg2") +else: + assert_equal("len(sys.argv)", len(sys.argv), 1) + +if os.getenv('ARGTEST_ONLY', False): + if failed: + sys.exit(1) + sys.exit(0) + +assert_equal("__package__", __package__, None) +assert_equal("sys.argv[0]", sys.argv[0], 'py-cmd_test.py') +if sys.version_info[0] == 2: + assert_equal("basename(sys.executable)", os.path.basename(sys.executable), 'py2-cmd') +else: + assert_equal("basename(sys.executable)", os.path.basename(sys.executable), 'py3-cmd') +assert_equal("sys.exec_prefix", sys.exec_prefix, sys.executable) +assert_equal("sys.prefix", sys.prefix, sys.executable) +assert_equal("site.ENABLE_USER_SITE", site.ENABLE_USER_SITE, None) + +if sys.version_info[0] == 2: + assert_equal("len(sys.path)", len(sys.path), 4) + assert_equal("sys.path[0]", sys.path[0], os.path.dirname(__file__)) + assert_equal("sys.path[1]", sys.path[1], "/extra") + assert_equal("sys.path[2]", sys.path[2], os.path.join(sys.executable, "internal")) + assert_equal("sys.path[3]", sys.path[3], os.path.join(sys.executable, "internal", "stdlib")) +else: + assert_equal("len(sys.path)", len(sys.path), 8) + assert_equal("sys.path[0]", sys.path[0], os.path.abspath(os.path.dirname(__file__))) + assert_equal("sys.path[1]", sys.path[1], "/extra") + assert_equal("sys.path[2]", sys.path[2], os.path.join(sys.executable, 'lib', 'python' + str(sys.version_info[0]) + str(sys.version_info[1]) + '.zip')) + assert_equal("sys.path[3]", sys.path[3], os.path.join(sys.executable, 'lib', 'python' + str(sys.version_info[0]) + '.' + str(sys.version_info[1]), '..')) + assert_equal("sys.path[4]", sys.path[4], os.path.join(sys.executable, 'lib', 'python' + str(sys.version_info[0]) + '.' + str(sys.version_info[1]))) + assert_equal("sys.path[5]", sys.path[5], os.path.join(sys.executable, 'lib', 'python' + str(sys.version_info[0]) + '.' + str(sys.version_info[1]), 'lib-dynload')) + assert_equal("sys.path[6]", sys.path[6], os.path.join(sys.executable, "internal")) + assert_equal("sys.path[7]", sys.path[7], os.path.join(sys.executable, "internal", "stdlib")) + +if failed: + sys.exit(1) + +import testpkg.pycmd_test diff --git a/python/tests/runtest.sh b/python/tests/runtest.sh index a319558ff..35941dc88 100755 --- a/python/tests/runtest.sh +++ b/python/tests/runtest.sh @@ -23,8 +23,11 @@ if [ -z $ANDROID_HOST_OUT ]; then exit 1 fi -if [ ! -f $ANDROID_HOST_OUT/nativetest64/par_test/par_test ]; then - echo "Run 'm par_test' first" +if [[ ( ! -f $ANDROID_HOST_OUT/nativetest64/par_test/par_test ) || + ( ! -f $ANDROID_HOST_OUT/nativetest64/par_test3/par_test3 ) || + ( ! -f $ANDROID_HOST_OUT/bin/py2-cmd ) || + ( ! -f $ANDROID_HOST_OUT/bin/py3-cmd )]]; then + echo "Run 'm par_test par_test3 py2-cmd py3-cmd' first" exit 1 fi @@ -36,4 +39,23 @@ PYTHONHOME= PYTHONPATH= $ANDROID_HOST_OUT/nativetest64/par_test/par_test PYTHONHOME=/usr $ANDROID_HOST_OUT/nativetest64/par_test/par_test PYTHONPATH=/usr $ANDROID_HOST_OUT/nativetest64/par_test/par_test +ARGTEST=true $ANDROID_HOST_OUT/nativetest64/par_test/par_test --arg1 arg2 + +PYTHONHOME= PYTHONPATH= $ANDROID_HOST_OUT/nativetest64/par_test3/par_test3 +PYTHONHOME=/usr $ANDROID_HOST_OUT/nativetest64/par_test3/par_test3 +PYTHONPATH=/usr $ANDROID_HOST_OUT/nativetest64/par_test3/par_test3 + +ARGTEST=true $ANDROID_HOST_OUT/nativetest64/par_test3/par_test3 --arg1 arg2 + +cd $(dirname ${BASH_SOURCE[0]}) + +PYTHONPATH=/extra $ANDROID_HOST_OUT/bin/py2-cmd py-cmd_test.py +PYTHONPATH=/extra $ANDROID_HOST_OUT/bin/py3-cmd py-cmd_test.py + +ARGTEST=true PYTHONPATH=/extra $ANDROID_HOST_OUT/bin/py2-cmd py-cmd_test.py arg1 arg2 +ARGTEST2=true PYTHONPATH=/extra $ANDROID_HOST_OUT/bin/py2-cmd py-cmd_test.py --arg1 arg2 + +ARGTEST=true PYTHONPATH=/extra $ANDROID_HOST_OUT/bin/py3-cmd py-cmd_test.py arg1 arg2 +ARGTEST2=true PYTHONPATH=/extra $ANDROID_HOST_OUT/bin/py3-cmd py-cmd_test.py --arg1 arg2 + echo "Passed!" diff --git a/python/tests/testpkg/__init__.py b/python/tests/testpkg/__init__.py new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/python/tests/testpkg/__init__.py diff --git a/python/tests/testpkg/par_test.py b/python/tests/testpkg/par_test.py index 22dd09564..ffad430e4 100644 --- a/python/tests/testpkg/par_test.py +++ b/python/tests/testpkg/par_test.py @@ -29,7 +29,13 @@ archive = sys.modules["__main__"].__loader__.archive assert_equal("__name__", __name__, "testpkg.par_test") assert_equal("__file__", __file__, os.path.join(archive, "testpkg/par_test.py")) -assert_equal("__package__", __package__, "testpkg") + +# Python3 is returning None here for me, and I haven't found any problems caused by this. +if sys.version_info[0] == 2: + assert_equal("__package__", __package__, "testpkg") +else: + assert_equal("__package__", __package__, None) + assert_equal("__loader__.archive", __loader__.archive, archive) assert_equal("__loader__.prefix", __loader__.prefix, "testpkg/") diff --git a/python/tests/testpkg/pycmd_test.py b/python/tests/testpkg/pycmd_test.py new file mode 100644 index 000000000..6b8a26301 --- /dev/null +++ b/python/tests/testpkg/pycmd_test.py @@ -0,0 +1,33 @@ +# Copyright 2018 Google Inc. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +import sys + +# This file checks the visible python state against expected values when run +# via the py*-cmd prebuilts + +failed = False +def assert_equal(what, a, b): + global failed + if a != b: + print("Expected %s('%s') == '%s'" % (what, a, b)) + failed = True + +assert_equal("__name__", __name__, "testpkg.pycmd_test") +assert_equal("basename(__file__)", os.path.basename(__file__), "pycmd_test.py") +assert_equal("__package__", __package__, "testpkg") + +if failed: + sys.exit(1) |