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 15import os 16import sys 17 18# This file checks the visible python state against expected values when run 19# inside a hermetic par file. 20 21failed = False 22def 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 28archive = sys.modules["__main__"].__loader__.archive 29 30assert_equal("__name__", __name__, "testpkg.par_test") 31fileName = __file__ 32if fileName.endswith('.pyc'): 33 fileName = fileName[:-1] 34assert_equal("__file__", fileName, os.path.join(archive, "testpkg/par_test.py")) 35 36assert_equal("__package__", __package__, "testpkg") 37 38assert_equal("__loader__.archive", __loader__.archive, archive) 39assert_equal("__loader__.prefix", __loader__.prefix, "testpkg/") 40 41if failed: 42 sys.exit(1) 43