Beispiel #1
0
def test_guess_db(capsys, hf):
    test_in_args = deepcopy(in_args)
    test_in_args.guess_database = True

    with pytest.raises(SystemExit):
        Db.command_line_ui(test_in_args, Db.DbBuddy(), skip_exit=True)

    out, err = capsys.readouterr()
    assert 'Nothing to return' in out

    with pytest.raises(SystemExit):
        Db.command_line_ui(test_in_args, Db.DbBuddy(",".join(ACCNS) + ",Casp9"), skip_exit=True)

    out, err = capsys.readouterr()
    assert hf.string2hash(out) == "4b3edb0272b02d8e18ce591304fdea1d"
Beispiel #2
0
def test_error(monkeypatch, capsys):
    monkeypatch.setattr(Db, "LiveShell", mock_systemexit)

    test_in_args = deepcopy(in_args)
    test_in_args.live_shell = True

    assert Db.command_line_ui(test_in_args, Db.DbBuddy(), skip_exit=True) is None

    monkeypatch.setattr(Db, "LiveShell", mock_fileexistserror)
    monkeypatch.setattr(br.TempFile, "save", lambda *_: True)
    monkeypatch.setattr(br, "send_traceback", lambda *_: True)
    capsys.readouterr()
    assert Db.command_line_ui(test_in_args, Db.DbBuddy(), skip_exit=True) is None
    out, err = capsys.readouterr()
    assert "can be loaded by launching DatabaseBuddy and using the 'load' command." in err
Beispiel #3
0
def test_exit(monkeypatch, capsys):
    class MockExitUsage(object):
        @staticmethod
        def increment(*args):
            print(args)
            return True

        @staticmethod
        def save():
            return True

    monkeypatch.setattr(br, "Usage", MockExitUsage)
    monkeypatch.setattr(Db, "LiveShell", lambda *_: True)
    test_in_args = deepcopy(in_args)

    with pytest.raises(SystemExit):
        Db.command_line_ui(test_in_args, Db.DbBuddy())
    out, err = capsys.readouterr()
    assert "('DatabaseBuddy', '%s', 'LiveShell', 0)" % Db.VERSION.short() in out
Beispiel #4
0
def test_retrieve_sequences(monkeypatch, capsys, sb_resources, hf):
    # Don't actually run anything, retrieve_summary() is tested elsewhere
    monkeypatch.setattr(Db, "retrieve_summary", lambda *_: True)
    monkeypatch.setattr(Db, "retrieve_sequences", lambda *_: True)
    test_in_args = deepcopy(in_args)
    test_in_args.retrieve_sequences = True

    dbbuddy = Db.DbBuddy()
    dbbuddy.failures = OrderedDict([("Foo", ValueError("Blahh")), ("Bar", AttributeError("Blahh"))])
    dbbuddy.records = sb_resources.get_one("f d").records
    for rec in dbbuddy.records:
        rec.id = re.sub("α", "", rec.id)
        rec.description = re.sub("α", "", rec.description)
    dbbuddy.records = OrderedDict([(rec.id, rec) for rec in dbbuddy.records])
    for accn, rec in dbbuddy.records.items():
        rec.size = len(rec)
        rec.record = rec

    with pytest.raises(SystemExit):
        Db.command_line_ui(test_in_args, dbbuddy)
    out, err = capsys.readouterr()
    assert dbbuddy.out_format == "fasta"
    assert hf.string2hash(out) == "5438dd48c22fd7b6cf2d3da637d333b6"
    assert err == """\
# ###################### Failures ###################### #
Foo
Blahh

Bar
Blahh
# ############################################## #

"""

    monkeypatch.setattr(br, "ask", lambda _, **kwargs: False)
    for accn, rec in dbbuddy.records.items():
        rec.size *= 100
    with pytest.raises(SystemExit):
        Db.command_line_ui(test_in_args, dbbuddy)
    out, err = capsys.readouterr()
    assert out == '\x1b[91mAborted...\n\n\x1b[m\x1b[40m'
Beispiel #5
0
def test_retrieve_accessions(monkeypatch):
    # Don't actually run anything, retrieve_summary() is tested elsewhere
    monkeypatch.setattr(Db, "retrieve_summary", lambda *_: True)
    test_in_args = deepcopy(in_args)
    test_in_args.retrieve_accessions = True
    dbbuddy = Db.DbBuddy()
    with pytest.raises(SystemExit):
        Db.command_line_ui(test_in_args, dbbuddy)
    assert dbbuddy.out_format == "ids"

    test_in_args.out_format = "genbank"
    dbbuddy = Db.DbBuddy(_out_format="genbank")
    with pytest.raises(SystemExit):
        Db.command_line_ui(test_in_args, dbbuddy)
    assert dbbuddy.out_format == "ids"

    for out_format in ["ids", "accessions", "full-summary", "summary"]:
        test_in_args.out_format = out_format
        dbbuddy = Db.DbBuddy(_out_format=out_format)
        with pytest.raises(SystemExit):
            Db.command_line_ui(test_in_args, dbbuddy)
        assert dbbuddy.out_format == out_format