def test_addons(): noop_file_name = os.path.join("anyci", "noop") + ".py" noop_file_name_pyc = os.path.join("anyci", "noop") + ".pyc" noop_file_path = os.path.join(ci_addons.home(), noop_file_name) noop_file_path_pyc = os.path.join(ci_addons.home(), noop_file_name_pyc) py_compile.main([noop_file_path]) if sys.version_info < (3, ): assert os.path.exists(noop_file_path_pyc) assert noop_file_name in ci_addons.addons() assert noop_file_name_pyc not in ci_addons.addons()
def test_install(tmpdir, capfd): noop = tmpdir.ensure('anyci/noop.py') ci_addons.install(str(tmpdir)) output_lines, _ = captured_lines(capfd) for addon in ci_addons.addons(): assert tmpdir.join(addon).exists() assert str(noop) + ' (skipped)' in output_lines assert str(tmpdir.join('appveyor', 'patch_vs2008.py')) in output_lines # # Check specifying --force overwrite add-ons already installed # ci_addons.install(str(tmpdir), force=True) output_lines, _ = captured_lines(capfd) assert str(noop) + ' (overwritten)' in output_lines # # Check that trying to overwrite original add-ons fails # with pytest.raises(RuntimeError): ci_addons.install(ci_addons.home())
def test_path(addon, extension, exception, expected_prefix_path): expected_path = os.path.join(ci_addons.home(), expected_prefix_path, addon) if not addon.endswith(extension): expected_path += extension if exception is None: assert ci_addons.path(addon) == expected_path else: with pytest.raises(exception): ci_addons.path(addon)
def test_get_commit_date(src_dir, subdirectory): # Import addon to facilitate testing sys.path.insert(0, os.path.join(ci_addons.home(), 'anyci')) pgr = __import__('publish_github_release') with push_dir(str(src_dir.ensure_dir(subdirectory))): _do_commit() output = getattr(pgr, 'get_commit_date')() assert re.match(r"^\d{8}$", output) # expected value of the form YYYYMMDD
def test_missing_git_repo(pgr_function, tmpdir): # Import addon to facilitate testing sys.path.insert(0, os.path.join(ci_addons.home(), 'anyci')) pgr = __import__('publish_github_release') with push_dir(str(tmpdir)): with pytest.raises( RuntimeError, match= r"Current directory is expected to be inside a git working tree.*" ): getattr(pgr, pgr_function)()
def src_dir(tmpdir_factory): # Import addon to facilitate testing sys.path.insert(0, os.path.join(ci_addons.home(), 'anyci')) tmp_dir = tmpdir_factory.mktemp("source") with push_dir(tmp_dir): tmp_dir.ensure("dist", dir=1).join('dummy.txt').write("# dummy package") _run("git init") # Arbitrary user name and email _run("git config user.email " "*****@*****.**") _run("git config user.name " "scikit-ci-addons-bot") return tmp_dir
def main(): """The main entry point to ``ci_addons``. This is installed as the script entry point. """ version_str = ("This is scikit-ci-addons version %s, imported from %s\n" % (ci_addons.__version__, os.path.abspath(ci_addons.__file__))) parser = argparse.ArgumentParser(description=ci_addons.__doc__) parser.add_argument( 'addon', metavar='ADDON', type=str, nargs='?', help='name of add-on to execute' ) parser.add_argument( 'arguments', metavar='ARG', type=str, nargs='*', help='add-on arguments' ) parser.add_argument( "--home", action="store_true", help="display directory where all add-ons can be found" ) parser.add_argument( "--list", action="store_true", help="list all available add-ons" ) parser.add_argument( "--path", type=str, help="display add-on path" ) parser.add_argument( "--install", type=str, metavar="DIR", help="install add-ons in the selected directory" ) parser.add_argument( "--version", action="version", version=version_str, help="display scikit-ci-addons version and import information" ) # If an add-on is selected, let's extract its arguments now. This will # prevent ci_addons parser from complaining about unknown parameters. addon_arguments = [] if len(sys.argv) > 1: try: ci_addons.path(sys.argv[1]) addon_arguments = sys.argv[2:] if len(addon_arguments) > 0 and addon_arguments[0] == '--': addon_arguments.pop(0) sys.argv = sys.argv[:2] except ci_addons.SKAddonsError: pass args = parser.parse_args() args.arguments = addon_arguments try: if args.home: # pragma: no cover print(ci_addons.home()) exit() if args.list: previous_collection = "" for addon in ci_addons.addons(): current_collection = addon.split(os.path.sep)[0] if previous_collection != current_collection: print("") print(addon) previous_collection = current_collection exit() if args.path is not None: # pragma: no cover print(ci_addons.path(args.path)) exit() if args.install is not None: # pragma: no cover ci_addons.install(args.install) exit() if all([not getattr(args, arg) for arg in ['addon', 'home', 'install', 'list', 'path']]): parser.print_usage() exit() ci_addons.execute(args.addon, args.arguments) except ci_addons.SKAddonsError as error: exit(error)
def test_execute(addon, capfd): ci_addons.execute(addon, ['foo', 'bar']) output_lines, _ = captured_lines(capfd) noop_path = os.path.join(ci_addons.home(), 'anyci/noop.py') assert noop_path + ' foo bar' in output_lines
def test_home(): expected_home = os.path.abspath(os.path.dirname(__file__) + '/..') assert ci_addons.home() == expected_home
from . import captured_lines, format_args_for_display def test_home(): expected_home = os.path.abspath(os.path.dirname(__file__) + '/..') assert ci_addons.home() == expected_home @pytest.mark.parametrize("addon, extension, exception, expected_prefix_path", [ ('anyci/noop', '.py', None, ""), ('anyci/noop.py', '.py', None, ""), ('noop', '.py', None, "anyci"), ('noop.py', '.py', None, "anyci"), ('appveyor/patch_vs2008', '.py', None, ""), (os.path.join(ci_addons.home(), 'appveyor/patch_vs2008'), '.py', None, ""), ('travis/run-with-pyenv.sh', '.sh', None, ""), ('install_cmake', '.py', RuntimeError, ""), ('nonexistent', '', RuntimeError, ""), ]) def test_path(addon, extension, exception, expected_prefix_path): expected_path = os.path.join(ci_addons.home(), expected_prefix_path, addon) if not addon.endswith(extension): expected_path += extension if exception is None: assert ci_addons.path(addon) == expected_path else: with pytest.raises(exception): ci_addons.path(addon)