bromano | c8c0d94 | 2021-02-26 04:17:57 +0100 | [diff] [blame] | 1 | # Copyright 2021 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 | """Tests for aar_embedded_proguard_extractor.""" |
| 15 | |
| 16 | import io |
| 17 | import os |
| 18 | import unittest |
| 19 | import zipfile |
| 20 | |
| 21 | from tools.android import aar_embedded_proguard_extractor |
| 22 | |
| 23 | |
| 24 | class AarEmbeddedProguardExtractor(unittest.TestCase): |
| 25 | """Unit tests for aar_embedded_proguard_extractor.py.""" |
| 26 | |
| 27 | # Python 2 alias |
| 28 | if not hasattr(unittest.TestCase, "assertCountEqual"): |
| 29 | |
| 30 | def assertCountEqual(self, *args): |
| 31 | return self.assertItemsEqual(*args) |
| 32 | |
| 33 | def setUp(self): |
| 34 | super(AarEmbeddedProguardExtractor, self).setUp() |
| 35 | os.chdir(os.environ["TEST_TMPDIR"]) |
| 36 | |
| 37 | def testNoProguardTxt(self): |
| 38 | aar = zipfile.ZipFile(io.BytesIO(), "w") |
| 39 | proguard_file = io.BytesIO() |
| 40 | aar_embedded_proguard_extractor.ExtractEmbeddedProguard(aar, proguard_file) |
| 41 | proguard_file.seek(0) |
| 42 | self.assertEqual(b"", proguard_file.read()) |
| 43 | |
| 44 | def testWithProguardTxt(self): |
| 45 | aar = zipfile.ZipFile(io.BytesIO(), "w") |
| 46 | aar.writestr("proguard.txt", "hello world") |
| 47 | proguard_file = io.BytesIO() |
| 48 | aar_embedded_proguard_extractor.ExtractEmbeddedProguard(aar, proguard_file) |
| 49 | proguard_file.seek(0) |
| 50 | self.assertEqual(b"hello world", proguard_file.read()) |
| 51 | |
| 52 | |
| 53 | if __name__ == "__main__": |
| 54 | unittest.main() |