|
| 1 | +# Copyright 2018 The Bazel Authors. 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 unittest |
| 17 | +import zipfile |
| 18 | + |
| 19 | + |
| 20 | +class WheelTest(unittest.TestCase): |
| 21 | + def test_py_library_wheel(self): |
| 22 | + filename = os.path.join(os.environ['TEST_SRCDIR'], |
| 23 | + 'io_bazel_rules_python', 'experimental', |
| 24 | + 'examples', 'wheel', |
| 25 | + 'example_minimal_library-0.0.1-py3-none-any.whl') |
| 26 | + with zipfile.ZipFile(filename) as zf: |
| 27 | + self.assertEquals( |
| 28 | + zf.namelist(), |
| 29 | + ['experimental/examples/wheel/lib/module_with_data.py', |
| 30 | + 'experimental/examples/wheel/lib/simple_module.py', |
| 31 | + 'example_minimal_library-0.0.1.dist-info/WHEEL', |
| 32 | + 'example_minimal_library-0.0.1.dist-info/METADATA', |
| 33 | + 'example_minimal_library-0.0.1.dist-info/RECORD']) |
| 34 | + |
| 35 | + def test_py_package_wheel(self): |
| 36 | + filename = os.path.join(os.environ['TEST_SRCDIR'], |
| 37 | + 'io_bazel_rules_python', 'experimental', |
| 38 | + 'examples', 'wheel', |
| 39 | + 'example_minimal_package-0.0.1-py3-none-any.whl') |
| 40 | + with zipfile.ZipFile(filename) as zf: |
| 41 | + self.assertEquals( |
| 42 | + zf.namelist(), |
| 43 | + ['experimental/examples/wheel/lib/data.txt', |
| 44 | + 'experimental/examples/wheel/lib/module_with_data.py', |
| 45 | + 'experimental/examples/wheel/lib/simple_module.py', |
| 46 | + 'experimental/examples/wheel/main.py', |
| 47 | + 'example_minimal_package-0.0.1.dist-info/WHEEL', |
| 48 | + 'example_minimal_package-0.0.1.dist-info/METADATA', |
| 49 | + 'example_minimal_package-0.0.1.dist-info/RECORD']) |
| 50 | + |
| 51 | + def test_customized_wheel(self): |
| 52 | + filename = os.path.join(os.environ['TEST_SRCDIR'], |
| 53 | + 'io_bazel_rules_python', 'experimental', |
| 54 | + 'examples', 'wheel', |
| 55 | + 'example_customized-0.0.1-py3-none-any.whl') |
| 56 | + with zipfile.ZipFile(filename) as zf: |
| 57 | + self.assertEquals( |
| 58 | + zf.namelist(), |
| 59 | + ['experimental/examples/wheel/lib/data.txt', |
| 60 | + 'experimental/examples/wheel/lib/module_with_data.py', |
| 61 | + 'experimental/examples/wheel/lib/simple_module.py', |
| 62 | + 'experimental/examples/wheel/main.py', |
| 63 | + 'example_customized-0.0.1.dist-info/WHEEL', |
| 64 | + 'example_customized-0.0.1.dist-info/METADATA', |
| 65 | + 'example_customized-0.0.1.dist-info/entry_points.txt', |
| 66 | + 'example_customized-0.0.1.dist-info/RECORD']) |
| 67 | + record_contents = zf.read( |
| 68 | + 'example_customized-0.0.1.dist-info/RECORD') |
| 69 | + wheel_contents = zf.read( |
| 70 | + 'example_customized-0.0.1.dist-info/WHEEL') |
| 71 | + metadata_contents = zf.read( |
| 72 | + 'example_customized-0.0.1.dist-info/METADATA') |
| 73 | + # The entries are guaranteed to be sorted. |
| 74 | + self.assertEquals(record_contents, b"""\ |
| 75 | +example_customized-0.0.1.dist-info/METADATA,sha256=TeeEmokHE2NWjkaMcVJuSAq4_AXUoIad2-SLuquRmbg,372 |
| 76 | +example_customized-0.0.1.dist-info/RECORD,, |
| 77 | +example_customized-0.0.1.dist-info/WHEEL,sha256=F01lGfVCzcXUzzQHzUkBmXAcu_TXd5zqMLrvrspncJo,85 |
| 78 | +example_customized-0.0.1.dist-info/entry_points.txt,sha256=olLJ8FK88aft2pcdj4BD05F8Xyz83Mo51I93tRGT2Yk,74 |
| 79 | +experimental/examples/wheel/lib/data.txt,sha256=9vJKEdfLu8bZRArKLroPZJh1XKkK3qFMXiM79MBL2Sg,12 |
| 80 | +experimental/examples/wheel/lib/module_with_data.py,sha256=K_IGAq_CHcZX0HUyINpD1hqSKIEdCn58d9E9nhWF2EA,636 |
| 81 | +experimental/examples/wheel/lib/simple_module.py,sha256=72-91Dm6NB_jw-7wYQt7shzdwvk5RB0LujIah8g7kr8,636 |
| 82 | +experimental/examples/wheel/main.py,sha256=E0xCyiPg6fCo4IrFmqo_tqpNGtk1iCewobqD0_KlFd0,935 |
| 83 | +""") |
| 84 | + self.assertEquals(wheel_contents, b"""\ |
| 85 | +Wheel-Version: 1.0 |
| 86 | +Generator: wheelmaker 1.0 |
| 87 | +Root-Is-Purelib: true |
| 88 | +Tag: py3-none-any |
| 89 | +""") |
| 90 | + self.assertEquals(metadata_contents, b"""\ |
| 91 | +Metadata-Version: 2.1 |
| 92 | +Name: example_customized |
| 93 | +Version: 0.0.1 |
| 94 | +Author: Example Author with non-ascii characters: \xc5\xbc\xc3\xb3\xc5\x82w |
| 95 | + |
| 96 | +Home-page: www.example.com |
| 97 | +License: Apache 2.0 |
| 98 | +Classifier: License :: OSI Approved :: Apache Software License |
| 99 | +Classifier: Intended Audience :: Developers |
| 100 | +Requires-Dist: pytest |
| 101 | +
|
| 102 | +This is a sample description of a wheel. |
| 103 | +""") |
| 104 | + |
| 105 | + |
| 106 | +if __name__ == '__main__': |
| 107 | + unittest.main() |
0 commit comments