def test_help(): """Running command with --help succeeds.""" sys.argv = ["pidiff", "--help"] with raises(SystemExit) as exc: command.main() assert exc.value.code == 0
def test_missing_module(workdir): """Command fails if module name is not provided and autodetect fails""" sys.argv = ["pidiff", "--workdir", workdir, "pkg1", "pkg2"] with mock.patch("subprocess.Popen") as mock_popen: mock_popen.side_effect = fake_popen with raises(SystemExit) as exc: command.main() assert exc.value.code == 32
def test_options_from_ini(workdir, tmpdir, caplog): # top-level dir tmpdir.join("pidiff.ini").write( dedent(""" [pidiff] enable= added-var-args disable= N400 added-var-args added-argument """)) # Put reverse config in setup.cfg, # this shows setup.cfg is lower priority tmpdir.join("setup.cfg").write( dedent(""" [pidiff] disable= added-var-args enable= N400 added-var-args added-argument """)) tmpdir.mkdir("subdir").join("pidiff.ini").write( dedent(""" [something] some=unrelated,config """)) os.chdir(str(tmpdir.join("subdir"))) caplog.set_level(logging.INFO) sys.argv = [ "pidiff", "--workdir", workdir, "testpkg==1.0.0", "testpkg==1.1.0", "tests.test_api.signatures", ] caplog.set_level(logging.INFO) with mock.patch("subprocess.Popen") as mock_popen: mock_popen.side_effect = fake_popen with raises(SystemExit) as exc: command.main() checklogs("diff_signatures_with_options", caplog, workdir) assert exc.value.code == 99
def test_genversion_diff(workdir, testapi, exitcode, stdout, capsys): sys.argv = [ "pidiff", "--workdir", workdir, "--gen-version", "foopkg==1.0.0", "foopkg==1.1.0", "tests.test_api.%s" % testapi, ] with mock.patch("subprocess.Popen") as mock_popen: mock_popen.side_effect = fake_popen with raises(SystemExit) as exc: command.main() assert exc.value.code == exitcode (out, _) = capsys.readouterr() # It should have output *exactly* the expected stdout assert out == stdout
def test_typical_diff(workdir, testapi, testname, exitcode, extra_args, caplog): sys.argv = [ "pidiff", "--workdir", workdir, "foopkg==1.0.0", "foopkg==1.1.0", "tests.test_api.%s" % testapi, ] sys.argv.extend(extra_args) caplog.set_level(logging.INFO) with mock.patch("subprocess.Popen") as mock_popen: mock_popen.side_effect = fake_popen with raises(SystemExit) as exc: command.main() testname = testname or testapi checklogs("typical_diff_%s" % testname, caplog, workdir) assert exc.value.code == exitcode