Esempio n. 1
0
def test_branch_commit_tag(caplog):
    caplog.set_level(logging.DEBUG, logger=_PKG_NAME)

    options = [
        (False, True, True),
        (True, False, True),
        (True, True, False),
        (True, True, True),
    ]

    caplog.clear()
    for b, c, t in options:
        install('does-not-matter', branch=b, commit=c, tag=t)
        update('does-not-matter', branch=b, commit=c, tag=t)
    for r in caplog.records:
        assert r.levelname == 'ERROR'
        assert r.message == 'Can only specify a branch, a commit or a tag (not multiple options simultaneously)'

    cached_has_git = bool(utils.has_git)
    utils.has_git = False

    caplog.clear()
    install('does-not-matter', commit='does-not-matter')
    r = caplog.records[0]
    assert r.levelname == 'ERROR'
    assert r.message == 'Cannot install from a commit because git is not installed'

    caplog.clear()
    update('does-not-matter', commit='does-not-matter')
    r = caplog.records[0]
    assert r.levelname == 'ERROR'
    assert r.message == 'Cannot update from a commit because git is not installed'

    utils.has_git = cached_has_git
Esempio n. 2
0
def test_issue8_b():
    # test issue 8 in Python 2.7 since pr-omega-logger requires Python 3.6+
    repo = 'pr-webpage-text'
    pkg = 'webpage-text'
    assert pkg not in installed()
    install(repo, yes=True)
    assert pkg in installed()
    update(pkg, branch='main', yes=True)
    assert pkg in installed()
    uninstall(pkg, yes=True)
    assert pkg not in installed()
Esempio n. 3
0
def test_issue8_a():
    repo = 'pr-omega-logger'
    pkg = 'omega-logger'
    assert pkg not in installed()
    install(repo, yes=True)
    assert pkg in installed()
    update(pkg, branch='main', yes=True)
    assert pkg in installed()

    # msl-equipment, msl-io and msl-loadlib are also installed
    # do not include any packages in the call to uninstall() to
    # uninstall all MSL packages that were installed in this test
    uninstall(yes=True)
    installed_ = installed()
    assert pkg not in installed_
    assert 'msl-equipment' not in installed_
    assert 'msl-loadlib' not in installed_
    assert 'msl-io' not in installed_
Esempio n. 4
0
def test_from_commit():
    cleanup()

    commit1 = 'b2581039e4e3f2ffe2599927d589809efbb9a1ff'
    commit2 = '12591bade80321c3a165f7a7364ef13f568d622b'

    install('loadlib', yes=True, commit=commit1)

    # reload all msl modules
    for name, module in sys.modules.copy().items():
        if name.startswith('msl'):
            try:
                reload(module)
            except:
                pass

    # the version ends with the expected commit hash
    packages = installed()
    expected = '0.9.0.dev0+{}'.format(commit1[:7])
    assert 'msl-loadlib' in packages
    assert packages['msl-loadlib']['version'] == expected
    msl_loadlib = importlib.import_module('msl.loadlib')
    assert msl_loadlib.__version__ == expected

    update('loadlib', yes=True, commit=commit2)

    # reload all msl modules
    for name, module in sys.modules.copy().items():
        if name.startswith('msl'):
            try:
                reload(module)
            except:
                pass

    # the version ends with the expected commit hash
    packages = installed()
    expected = '0.9.1.dev0+{}'.format(commit2[:7])
    assert 'msl-loadlib' in packages
    assert packages['msl-loadlib']['version'] == expected
    msl_loadlib = importlib.import_module('msl.loadlib')
    assert msl_loadlib.__version__ == expected

    uninstall('loadlib', yes=True)
    assert 'msl-loadlib' not in installed()
Esempio n. 5
0
def test_msl_and_non_msl():
    cleanup()

    # msl-io has xlrd<2.0 as a dependency
    # make sure that xlrd is not >2.0 after updating

    install('loadlib==0.7.0', 'io', yes=True)

    # reload all msl modules
    for name, module in sys.modules.copy().items():
        if name.startswith('msl'):
            try:
                reload(module)
            except:
                pass

    xlrd = importlib.import_module('xlrd')
    assert xlrd.__version__ == '1.2.0'

    outdated = utils.outdated_pypi_packages()
    assert 'msl-loadlib' not in outdated
    assert 'msl-io' not in outdated

    # strange, this assert fails in Python 3.5 and does not
    # depend on the version of pip (checked back to pip 10.0)
    if sys.version_info[:2] != (3, 5):
        assert outdated['xlrd']['version'] == '<2.0'

    msl_loadlib = importlib.import_module('msl.loadlib')
    assert installed()['msl-loadlib']['version'] == '0.7.0'
    assert msl_loadlib.__version__ == '0.7.0'

    update('loadlib==0.8.0', include_non_msl=True, yes=True)

    assert reload(xlrd).__version__ == '1.2.0'

    assert installed()['msl-loadlib']['version'] == '0.8.0'
    assert reload(msl_loadlib).__version__ == '0.8.0'

    uninstall('loadlib', 'io', yes=True)
    installed_ = installed()
    assert 'msl-loadlib' not in installed_
    assert 'msl-io' not in installed_
Esempio n. 6
0
def test_log_output(caplog):
    # checks that the logging messages have the expected output
    caplog.set_level(logging.DEBUG, logger=_PKG_NAME)

    # install MSL-LoadLib version 0.5.0
    install('loadlib==0.5.0', yes=True)

    # make sure that MSL-LoadLib is installed
    assert 'msl-loadlib' in installed()

    # install a package that does not exist
    install('does_not_exist', yes=True)

    # install MSL-LoadLib
    install('loadlib', yes=True)

    # check that py4j is not installed
    with pytest.raises(ImportError):
        import py4j

    # update MSL-LoadLib
    update('loadlib[java]==0.6.0', yes=True)

    # py4j should now be installed
    import py4j

    # update a package that is not an MSL package
    update('colorama', yes=True)

    # uninstall a package that is not an MSL package
    uninstall('colorama', yes=True)
    import colorama  # still installed

    # install a package that is not part of the msl namespace
    install('GTC<1.3', yes=True, pip_options=['--no-deps'])

    # make sure that GTC is installed
    assert 'GTC' in installed()

    # update GTC -> invalid branch
    update('GTC', yes=True, branch='invalid')

    # update GTC -> invalid tag
    update('GTC', yes=True, tag='invalid')

    # update GTC -> tag=v1.3.1
    update('GTC', yes=True, tag='v1.3.1')

    # uninstall GTC
    uninstall('GTC', yes=True)

    # make sure that GTC is not installed but msl-loadlib is still installed
    assert 'GTC' not in installed()
    assert 'msl-loadlib' in installed()

    # uninstall MSL-LoadLib
    uninstall('loadlib', yes=True)

    # make sure that MSL-LoadLib is not installed
    assert 'msl-loadlib' not in installed()

    #
    # the expected logging messages
    #
    exec_path = os.path.dirname(sys.executable)
    u = 'u' if sys.version_info.major == 2 else ''
    expected = [
        # msl install loadlib==0.5.0
        'Loaded the cached information about the PyPI packages',
        'Loaded the cached information about the GitHub repositories',
        'Getting the packages from {}'.format(exec_path),
        '\n\x1b[39mThe following MSL packages will be \x1b[36mINSTALLED\x1b[39m:\n\n  msl-loadlib  0.5.0    [PyPI]',
        '',
        "Installing {}'msl-loadlib' from PyPI".format(u),

        # check if msl-loadlib is installed
        'Getting the packages from {}'.format(exec_path),

        # msl install does_not_exist -> a that package does not exist
        'Loaded the cached information about the PyPI packages',
        'Loaded the cached information about the GitHub repositories',
        'Getting the packages from {}'.format(exec_path),
        "No MSL packages match 'does_not_exist'",
        'No MSL packages to install',

        # msl install loadlib -> already installed
        'Loaded the cached information about the PyPI packages',
        'Loaded the cached information about the GitHub repositories',
        'Getting the packages from {}'.format(exec_path),
        "The {}'msl-loadlib' package is already installed -- use the update command"
        .format(u),
        'No MSL packages to install',

        # msl update loadlib[java]==0.6.0
        'Loaded the cached information about the PyPI packages',
        'Loaded the cached information about the GitHub repositories',
        'Getting the packages from {}'.format(exec_path),
        '\n\x1b[39mThe following MSL packages will be \x1b[36mUPDATED\x1b[39m:\n\n  msl-loadlib[java]  0.5.0 --> 0.6.0  [PyPI]',
        '',
        "Updating {}'msl-loadlib' from PyPI".format(u),

        # msl update colorama -> not an MSL package
        'Loaded the cached information about the PyPI packages',
        'Loaded the cached information about the GitHub repositories',
        'Getting the packages from {}'.format(exec_path),
        "No MSL packages match 'colorama'",
        '\x1b[39mNo packages to update\x1b[39m',

        # msl uninstall colorama -> not an MSL package
        'Getting the packages from {}'.format(exec_path),
        "No MSL packages match 'colorama'",
        'No MSL packages to uninstall',

        # install GTC
        'Loaded the cached information about the PyPI packages',
        'Loaded the cached information about the GitHub repositories',
        'Getting the packages from {}'.format(exec_path),
        '\n\x1b[39mThe following MSL packages will be \x1b[36mINSTALLED\x1b[39m:\n\n  GTC  <1.3  [PyPI]',
        '',
        "Installing {}'GTC' from PyPI".format(u),

        # check if GTC is installed
        'Getting the packages from {}'.format(exec_path),

        # update GTC -> invalid branch
        'Loaded the cached information about the PyPI packages',
        'Loaded the cached information about the GitHub repositories',
        'Getting the packages from {}'.format(exec_path),
        "Cannot update {}'GTC' -- The 'invalid' branch does not exist".format(
            u),
        '\x1b[39mNo packages to update\x1b[39m',

        # update GTC -> invalid tag
        'Loaded the cached information about the PyPI packages',
        'Loaded the cached information about the GitHub repositories',
        'Getting the packages from {}'.format(exec_path),
        "Cannot update {}'GTC' -- The 'invalid' tag does not exist".format(u),
        '\x1b[39mNo packages to update\x1b[39m',

        # update GTC -> tag=v1.3.1
        'Loaded the cached information about the PyPI packages',
        'Loaded the cached information about the GitHub repositories',
        'Getting the packages from {}'.format(exec_path),
        '\n\x1b[39mThe following MSL packages will be \x1b[36mUPDATED\x1b[39m:\n\n  GTC  1.2.1 --> [tag:v1.3.1]  [GitHub]',
        '',
        "Updating {}'GTC' from GitHub[v1.3.1]".format(u),

        # msl uninstall GTC
        'Getting the packages from {}'.format(exec_path),
        '\n\x1b[39mThe following MSL packages will be \x1b[36mREMOVED\x1b[39m:\n\n  GTC  1.3.1 ',
        '',

        # checking that GTC is not installed
        'Getting the packages from {}'.format(exec_path),

        # checking that msl-loadlib is still installed
        'Getting the packages from {}'.format(exec_path),

        # msl uninstall loadlib
        'Getting the packages from {}'.format(exec_path),
        '\n\x1b[39mThe following MSL packages will be \x1b[36mREMOVED\x1b[39m:\n\n  msl-loadlib  0.6.0 ',
        '',

        # check that msl-loadlib is not installed
        'Getting the packages from {}'.format(exec_path),
    ]

    for index, record in enumerate(caplog.records):
        assert expected[index] == record.message