• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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")
31assert_equal("__file__", __file__, os.path.join(archive, "testpkg/par_test.py"))
32
33# Python3 is returning None here for me, and I haven't found any problems caused by this.
34if sys.version_info[0] == 2:
35  assert_equal("__package__", __package__, "testpkg")
36else:
37  assert_equal("__package__", __package__, None)
38
39assert_equal("__loader__.archive", __loader__.archive, archive)
40assert_equal("__loader__.prefix", __loader__.prefix, "testpkg/")
41
42if failed:
43    sys.exit(1)
44