1
1
import unittest
2
- from unittest import mock
2
+ from unittest import mock , skipIf
3
+
4
+ import sys
3
5
4
6
from pythonforandroid .prerequisites import (
5
7
JDKPrerequisite ,
@@ -18,6 +20,7 @@ class PrerequisiteSetUpBaseClass:
18
20
def setUp (self ):
19
21
self .mandatory = dict (linux = False , darwin = False )
20
22
self .installer_is_supported = dict (linux = False , darwin = False )
23
+ self .expected_homebrew_formula_name = ""
21
24
22
25
def test_is_mandatory_on_darwin (self ):
23
26
assert self .prerequisite .mandatory ["darwin" ] == self .mandatory ["darwin" ]
@@ -37,6 +40,26 @@ def test_installer_is_supported_on_linux(self):
37
40
== self .installer_is_supported ["linux" ]
38
41
)
39
42
43
+ def test_darwin_pkg_config_location (self ):
44
+ self .assertEqual (self .prerequisite .darwin_pkg_config_location (), "" )
45
+
46
+ def test_linux_pkg_config_location (self ):
47
+ self .assertEqual (self .prerequisite .linux_pkg_config_location (), "" )
48
+
49
+ @skipIf (sys .platform != "darwin" , "Only run on macOS" )
50
+ def test_pkg_config_location_property__darwin (self ):
51
+ self .assertEqual (
52
+ self .prerequisite .pkg_config_location ,
53
+ self .prerequisite .darwin_pkg_config_location (),
54
+ )
55
+
56
+ @skipIf (sys .platform != "linux" , "Only run on Linux" )
57
+ def test_pkg_config_location_property__linux (self ):
58
+ self .assertEqual (
59
+ self .prerequisite .pkg_config_location ,
60
+ self .prerequisite .linux_pkg_config_location (),
61
+ )
62
+
40
63
41
64
class TestJDKPrerequisite (PrerequisiteSetUpBaseClass , unittest .TestCase ):
42
65
def setUp (self ):
@@ -76,6 +99,8 @@ def setUp(self):
76
99
self .mandatory = dict (linux = False , darwin = True )
77
100
self .installer_is_supported = dict (linux = False , darwin = True )
78
101
self .prerequisite = OpenSSLPrerequisite ()
102
+ self .expected_homebrew_formula_name = "openssl@1.1"
103
+ self .expected_homebrew_location_prefix = "/opt/homebrew/opt/openssl@1.1"
79
104
80
105
@mock .patch (
81
106
"pythonforandroid.prerequisites.Prerequisite._darwin_get_brew_formula_location_prefix"
@@ -84,17 +109,31 @@ def test_darwin_checker(self, _darwin_get_brew_formula_location_prefix):
84
109
_darwin_get_brew_formula_location_prefix .return_value = None
85
110
self .assertFalse (self .prerequisite .darwin_checker ())
86
111
_darwin_get_brew_formula_location_prefix .return_value = (
87
- "/opt/homebrew/opt/openssl@1.1"
112
+ self . expected_homebrew_location_prefix
88
113
)
89
114
self .assertTrue (self .prerequisite .darwin_checker ())
90
115
_darwin_get_brew_formula_location_prefix .assert_called_with (
91
- "openssl@1.1" , installed = True
116
+ self . expected_homebrew_formula_name , installed = True
92
117
)
93
118
94
119
@mock .patch ("pythonforandroid.prerequisites.subprocess.check_output" )
95
120
def test_darwin_installer (self , check_output ):
96
121
self .prerequisite .darwin_installer ()
97
- check_output .assert_called_once_with (["brew" , "install" , "openssl@1.1" ])
122
+ check_output .assert_called_once_with (
123
+ ["brew" , "install" , self .expected_homebrew_formula_name ]
124
+ )
125
+
126
+ @mock .patch (
127
+ "pythonforandroid.prerequisites.Prerequisite._darwin_get_brew_formula_location_prefix"
128
+ )
129
+ def test_darwin_pkg_config_location (self , _darwin_get_brew_formula_location_prefix ):
130
+ _darwin_get_brew_formula_location_prefix .return_value = (
131
+ self .expected_homebrew_location_prefix
132
+ )
133
+ self .assertEqual (
134
+ self .prerequisite .darwin_pkg_config_location (),
135
+ f"{ self .expected_homebrew_location_prefix } /lib/pkgconfig" ,
136
+ )
98
137
99
138
100
139
class TestAutoconfPrerequisite (PrerequisiteSetUpBaseClass , unittest .TestCase ):
0 commit comments