Test that class :class:`~pythonforandroid.archs.ArchARM` returns some expected attributes and environment variables. .. note:: Here we mock two methods: - `ensure_dir` because we don't want to create any directory - `shutil.which
(self, mock_ensure_dir, mock_shutil_which)
| 95 | @mock.patch("shutil.which") |
| 96 | @mock.patch("pythonforandroid.build.ensure_dir") |
| 97 | def test_arch_arm(self, mock_ensure_dir, mock_shutil_which): |
| 98 | """ |
| 99 | Test that class :class:`~pythonforandroid.archs.ArchARM` returns some |
| 100 | expected attributes and environment variables. |
| 101 | |
| 102 | .. note:: |
| 103 | Here we mock two methods: |
| 104 | |
| 105 | - `ensure_dir` because we don't want to create any directory |
| 106 | - `shutil.which` because otherwise we will |
| 107 | get an error when trying to find the compiler (we are setting |
| 108 | some fake paths for our android sdk and ndk so probably will |
| 109 | not exist) |
| 110 | |
| 111 | """ |
| 112 | mock_shutil_which.return_value = self.expected_compiler |
| 113 | mock_ensure_dir.return_value = True |
| 114 | |
| 115 | arch = ArchARM(self.ctx) |
| 116 | self.assertEqual(arch.arch, "armeabi") |
| 117 | self.assertEqual(arch.__str__(), "armeabi") |
| 118 | self.assertEqual(arch.command_prefix, "arm-linux-androideabi") |
| 119 | self.assertEqual(arch.target, "armv7a-linux-androideabi21") |
| 120 | arch = ArchARM(self.ctx) |
| 121 | |
| 122 | # Check environment flags |
| 123 | env = arch.get_env() |
| 124 | self.assertIsInstance(env, dict) |
| 125 | self.assertEqual( |
| 126 | expected_env_gcc_keys, set(env.keys()) & expected_env_gcc_keys |
| 127 | ) |
| 128 | |
| 129 | # check shutil.which calls |
| 130 | mock_shutil_which.assert_called_once_with( |
| 131 | self.expected_compiler, path=environ["PATH"] |
| 132 | ) |
| 133 | |
| 134 | # check gcc compilers |
| 135 | self.assertEqual(env["CC"].split()[0], self.expected_compiler) |
| 136 | self.assertEqual(env["CXX"].split()[0], self.expected_compiler + "++") |
| 137 | # check android binaries |
| 138 | self.assertEqual( |
| 139 | env["STRIP"].split()[0], |
| 140 | os.path.join( |
| 141 | self.ctx._ndk_dir, |
| 142 | f"toolchains/llvm/prebuilt/{self.ctx.ndk.host_tag}/bin", |
| 143 | "llvm-strip", |
| 144 | ) |
| 145 | ) |
| 146 | self.assertEqual( |
| 147 | env["READELF"].split()[0], |
| 148 | os.path.join( |
| 149 | self.ctx._ndk_dir, |
| 150 | f"toolchains/llvm/prebuilt/{self.ctx.ndk.host_tag}/bin", |
| 151 | "llvm-readelf", |
| 152 | ) |
| 153 | ) |
| 154 |