# This Source Code Form is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the MPL was not distributed with this file, # You can obtain one at http://mozilla.org/MPL/2.0/.
import os import shutil import sys
import mozunit import pytest from moztest.selftest.fixtures import binary_fixture # noqa: F401 from mozversion import errors, get_version
"""test getting application version information from a binary path"""
@pytest.mark.skipif( not hasattr(os, "symlink"), reason="os.symlink not supported on this platform"
) def test_symlinked_binary(fake_binary, application_ini, platform_ini, tmpdir): # create a symlink of the binary in another directory and check # version against this symlink
symlink = str(tmpdir.join("symlink"))
os.symlink(fake_binary, symlink)
_check_version(get_version(symlink))
def test_with_ini_files_on_osx(
fake_binary, application_ini, platform_ini, monkeypatch, tmpdir
):
monkeypatch.setattr(sys, "platform", "darwin") # get_version is working with ini files next to the binary
_check_version(get_version(binary=fake_binary))
# or if they are in the Resources dir # in this case the binary must be in a Contents dir, next # to the Resources dir
contents_dir = tmpdir.mkdir("Contents")
moved_binary = str(contents_dir.join(os.path.basename(fake_binary)))
shutil.move(fake_binary, moved_binary)
def test_invalid_binary_path(tmpdir): with pytest.raises(IOError):
get_version(str(tmpdir.join("invalid")))
def test_without_ini_files(fake_binary): """With missing ini files an exception should be thrown""" with pytest.raises(errors.AppNotFoundError):
get_version(fake_binary)
def test_without_platform_ini_file(fake_binary, application_ini): """With a missing platform.ini file an exception should be thrown""" with pytest.raises(errors.AppNotFoundError):
get_version(fake_binary)
def test_without_application_ini_file(fake_binary, platform_ini): """With a missing application.ini file an exception should be thrown""" with pytest.raises(errors.AppNotFoundError):
get_version(fake_binary)
def test_with_exe(application_ini, platform_ini, tmpdir): """Test that we can resolve .exe files"""
binary = tmpdir.join("binary.exe")
binary.write("foobar")
_check_version(get_version(os.path.splitext(str(binary))[0]))
def test_not_found_with_binary_specified(fake_binary): with pytest.raises(errors.LocalAppNotFoundError):
get_version(fake_binary)
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.