File tree Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Original file line number Diff line number Diff line change 99# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1010# See the License for the specific language governing permissions and
1111# limitations under the License.
12+ import json
1213
1314from testinfra .modules .base import Module
1415
@@ -31,6 +32,7 @@ def is_installed(self):
3132
3233 - apk (Alpine)
3334 - apt (Debian, Ubuntu, ...)
35+ - brew (macOS)
3436 - pacman (Arch, Manjaro )
3537 - pkg (FreeBSD)
3638 - pkg_info (NetBSD)
@@ -94,6 +96,8 @@ def get_module_class(cls, host):
9496 return DebianPackage
9597 if host .exists ("rpm" ):
9698 return RpmPackage
99+ if host .exists ("brew" ):
100+ return HomebrewPackage
97101 raise NotImplementedError
98102
99103
@@ -216,3 +220,20 @@ def version(self):
216220 @property
217221 def release (self ):
218222 raise NotImplementedError
223+
224+
225+ class HomebrewPackage (Package ):
226+ @property
227+ def is_installed (self ):
228+ info = self .check_output ("brew info --formula --json %s" , self .name )
229+ return len (json .loads (info )[0 ]["installed" ]) > 0
230+
231+ @property
232+ def version (self ):
233+ info = self .check_output ("brew info --formula --json %s" , self .name )
234+ version = json .loads (info )[0 ]["installed" ][0 ]["version" ]
235+ return version
236+
237+ @property
238+ def release (self ):
239+ raise NotImplementedError
You can’t perform that action at this time.
0 commit comments