11import unittest
2- from unittest import mock
2+ from unittest import mock , skipIf
3+
4+ import sys
35
46from pythonforandroid .prerequisites import (
57 JDKPrerequisite ,
@@ -18,6 +20,7 @@ class PrerequisiteSetUpBaseClass:
1820 def setUp (self ):
1921 self .mandatory = dict (linux = False , darwin = False )
2022 self .installer_is_supported = dict (linux = False , darwin = False )
23+ self .expected_homebrew_formula_name = ""
2124
2225 def test_is_mandatory_on_darwin (self ):
2326 assert self .prerequisite .mandatory ["darwin" ] == self .mandatory ["darwin" ]
@@ -37,6 +40,26 @@ def test_installer_is_supported_on_linux(self):
3740 == self .installer_is_supported ["linux" ]
3841 )
3942
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+
4063
4164class TestJDKPrerequisite (PrerequisiteSetUpBaseClass , unittest .TestCase ):
4265 def setUp (self ):
@@ -76,6 +99,8 @@ def setUp(self):
7699 self .mandatory = dict (linux = False , darwin = True )
77100 self .installer_is_supported = dict (linux = False , darwin = True )
78101 self .prerequisite = OpenSSLPrerequisite ()
102+ self .expected_homebrew_formula_name = "openssl@1.1"
103+ self .expected_homebrew_location_prefix = "/opt/homebrew/opt/openssl@1.1"
79104
80105 @mock .patch (
81106 "pythonforandroid.prerequisites.Prerequisite._darwin_get_brew_formula_location_prefix"
@@ -84,17 +109,31 @@ def test_darwin_checker(self, _darwin_get_brew_formula_location_prefix):
84109 _darwin_get_brew_formula_location_prefix .return_value = None
85110 self .assertFalse (self .prerequisite .darwin_checker ())
86111 _darwin_get_brew_formula_location_prefix .return_value = (
87- "/opt/homebrew/opt/openssl@1.1"
112+ self . expected_homebrew_location_prefix
88113 )
89114 self .assertTrue (self .prerequisite .darwin_checker ())
90115 _darwin_get_brew_formula_location_prefix .assert_called_with (
91- "openssl@1.1" , installed = True
116+ self . expected_homebrew_formula_name , installed = True
92117 )
93118
94119 @mock .patch ("pythonforandroid.prerequisites.subprocess.check_output" )
95120 def test_darwin_installer (self , check_output ):
96121 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+ )
98137
99138
100139class TestAutoconfPrerequisite (PrerequisiteSetUpBaseClass , unittest .TestCase ):
0 commit comments