Dan Willemsen | 22e9244 | 2018-12-03 15:56:10 -0800 | [diff] [blame] | 1 | # Copyright 2018 Google Inc. All rights reserved. |
| 2 | # |
| 3 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | # you may not use this file except in compliance with the License. |
| 5 | # You may obtain a copy of the License at |
| 6 | # |
| 7 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | # |
| 9 | # Unless required by applicable law or agreed to in writing, software |
| 10 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | # See the License for the specific language governing permissions and |
| 13 | # limitations under the License. |
| 14 | |
| 15 | import os |
| 16 | import sys |
| 17 | |
| 18 | # This file checks the visible python state against expected values when run |
| 19 | # inside a hermetic par file. |
| 20 | |
| 21 | failed = False |
| 22 | def assert_equal(what, a, b): |
| 23 | global failed |
| 24 | if a != b: |
| 25 | print("Expected %s('%s') == '%s'" % (what, a, b)) |
| 26 | failed = True |
| 27 | |
| 28 | archive = sys.modules["__main__"].__loader__.archive |
| 29 | |
| 30 | assert_equal("__name__", __name__, "testpkg.par_test") |
Cole Faust | 5c503d1 | 2023-01-24 11:48:08 -0800 | [diff] [blame] | 31 | fileName = __file__ |
| 32 | if fileName.endswith('.pyc'): |
| 33 | fileName = fileName[:-1] |
| 34 | assert_equal("__file__", fileName, os.path.join(archive, "testpkg/par_test.py")) |
Dan Willemsen | 8d4d7be | 2019-11-04 19:21:04 -0800 | [diff] [blame] | 35 | |
Krzysztof KosiĆski | ebb25bd | 2022-09-20 02:16:33 +0000 | [diff] [blame^] | 36 | assert_equal("__package__", __package__, "testpkg") |
Dan Willemsen | 8d4d7be | 2019-11-04 19:21:04 -0800 | [diff] [blame] | 37 | |
Dan Willemsen | 22e9244 | 2018-12-03 15:56:10 -0800 | [diff] [blame] | 38 | assert_equal("__loader__.archive", __loader__.archive, archive) |
| 39 | assert_equal("__loader__.prefix", __loader__.prefix, "testpkg/") |
| 40 | |
| 41 | if failed: |
| 42 | sys.exit(1) |