Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions testinfra/modules/package.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,6 +9,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import json

from testinfra.modules.base import Module

Expand All@@ -31,6 +32,7 @@ def is_installed(self):

- apk (Alpine)
- apt (Debian, Ubuntu, ...)
- brew (macOS)
- pacman (Arch, Manjaro )
- pkg (FreeBSD)
- pkg_info (NetBSD)
Expand DownExpand Up@@ -92,6 +94,8 @@ def get_module_class(cls, host):
return DebianPackage
if host.exists("rpm"):
return RpmPackage
if host.exists("brew"):
return HomebrewPackage
raise NotImplementedError


Expand DownExpand Up@@ -214,3 +218,20 @@ def version(self):
@property
def release(self):
raise NotImplementedError


class HomebrewPackage(Package):
@property
def is_installed(self):
info = self.check_output("brew info --formula --json %s", self.name)
return len(json.loads(info)[0]["installed"]) > 0

@property
def version(self):
info = self.check_output("brew info --formula --json %s", self.name)
version = json.loads(info)[0]["installed"][0]["version"]
return version

@property
def release(self):
raise NotImplementedError