Skip to content

Commit e8e7c24

Browse files
committed
[test] Add test for openssl
1 parent 5aba04b commit e8e7c24

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed

tests/recipes/test_openssl.py

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import unittest
2+
from unittest import mock
3+
from tests.recipes.recipe_lib_test import BaseTestForMakeRecipe
4+
5+
6+
class TestOpensslRecipe(BaseTestForMakeRecipe, unittest.TestCase):
7+
"""
8+
An unittest for recipe :mod:`~pythonforandroid.recipes.openssl`
9+
"""
10+
11+
recipe_name = "openssl"
12+
sh_command_calls = ["perl"]
13+
14+
@mock.patch("pythonforandroid.recipes.openssl.sh.patch")
15+
@mock.patch("pythonforandroid.util.chdir")
16+
@mock.patch("pythonforandroid.build.ensure_dir")
17+
@mock.patch("pythonforandroid.archs.glob")
18+
@mock.patch("pythonforandroid.archs.find_executable")
19+
def test_build_arch(
20+
self,
21+
mock_find_executable,
22+
mock_glob,
23+
mock_ensure_dir,
24+
mock_current_directory,
25+
mock_sh_patch,
26+
):
27+
# We overwrite the base test method because we need to mock a little
28+
# more with this recipe (`sh.cp` and `sh.rm`)
29+
super(TestOpensslRecipe, self).test_build_arch()
30+
# make sure that the mocked methods are actually called
31+
mock_sh_patch.assert_called()
32+
33+
def test_versioned_url(self):
34+
self.assertEqual(
35+
self.recipe.url.format(url_version=self.recipe.url_version),
36+
self.recipe.versioned_url,
37+
)
38+
39+
def test_include_flags(self):
40+
inc = self.recipe.include_flags(self.arch)
41+
build_dir = self.recipe.get_build_dir(self.arch)
42+
for i in {"include/internal", "include/openssl"}:
43+
self.assertIn(f"-I{build_dir}/{i}", inc)
44+
45+
def test_link_flags(self):
46+
build_dir = self.recipe.get_build_dir(self.arch)
47+
openssl_version = self.recipe.version
48+
self.assertEqual(
49+
f" -L{build_dir} -lcrypto{openssl_version} -lssl{openssl_version}",
50+
self.recipe.link_flags(self.arch),
51+
)
52+
53+
def test_select_build_arch(self):
54+
expected_build_archs = {
55+
"armeabi": "android",
56+
"armeabi-v7a": "android-arm",
57+
"arm64-v8a": "android-arm64",
58+
"x86": "android-x86",
59+
"x86_64": "android-x86_64",
60+
}
61+
for arch in self.ctx.archs:
62+
self.assertEqual(
63+
expected_build_archs[arch.arch],
64+
self.recipe.select_build_arch(arch),
65+
)

0 commit comments

Comments
 (0)