示例#1
0
def test_liveshell_do_bash(monkeypatch, capsys):
    monkeypatch.setattr(Db.LiveShell, "cmdloop", mock_cmdloop)
    dbbuddy = Db.DbBuddy()
    crash_file = br.TempFile(byte_mode=True)
    liveshell = Db.LiveShell(dbbuddy, crash_file)
    capsys.readouterr()
    tmp_file = br.TempFile()
    liveshell.do_bash("echo 'hello from bash' > %s" % tmp_file.path)
    assert "hello from bash" in tmp_file.read()

    monkeypatch.setattr(
        "builtins.input",
        lambda _: "echo 'Line from input' > %s" % tmp_file.path)
    liveshell.do_bash(None)
    assert "Line from input" in tmp_file.read()

    liveshell.do_bash("cd /this/path/doesnt/exist")
    out, err = capsys.readouterr()
    assert "-sh: cd: /this/path/doesnt/exist: No such file or directory\n" in out

    tmp_dir = br.TempDir()
    tmp_dir.subfile("foo.txt")
    cwd = os.getcwd()
    liveshell.do_bash("cd %s" % tmp_dir.path)
    out, err = capsys.readouterr()
    assert tmp_dir.path in out
    assert os.path.isfile("foo.txt")
    os.chdir(cwd)
示例#2
0
def mock_urlopen_uniprot_summary(*args, **kwargs):
    print("mock_urlopen_uniprot_summary\nargs: %s\nkwargs: %s" %
          (args, kwargs))
    tmp_file = br.TempFile(byte_mode=True)
    tmp_file.write('''# Search: inx15
A8XEF9	A8XEF9_CAEBR	381	6238	Caenorhabditis briggsae	Innexin	Function (1); Sequence similarities (1); \
Subcellular location (2)
O61786	O61786_CAEEL	382	6239	Caenorhabditis elegans	Innexin	Function (1); Sequence similarities (1); \
Subcellular location (2)
A0A0H5SBJ0	A0A0H5SBJ0_BRUMA	129	6279	Brugia malayi (Filarial nematode worm)	Innexin	Function (1); Sequence \
similarities (1); Subcellular location (1)
E3MGD6	E3MGD6_CAERE	384	31234	Caenorhabditis remanei (Caenorhabditis vulgaris)	Innexin	Function (1); Sequence \
similarities (1); Subcellular location (2)
//
# Search: inx16
O61787	INX16_CAEEL	372	6239	Caenorhabditis elegans	Innexin-16 (Protein opu-16)	Function (1); Sequence \
similarities (1); Subcellular location (1)
A0A0V1AZ11	A0A0V1AZ11_TRISP	406	6334	Trichinella spiralis (Trichina worm)	Innexin	Caution (1); Function (1); \
Sequence similarities (1); Subcellular location (2)
A8XEF8	A8XEF8_CAEBR	374	6238	Caenorhabditis briggsae	Innexin	Function (1); Sequence similarities (1); \
Subcellular location (2)
A0A0B2VB60	A0A0B2VB60_TOXCA	366	6265	Toxocara canis (Canine roundworm)	Innexin	Caution (2); Function (1); \
Sequence similarities (1); Subcellular location (1)
A0A0V0W5E2	A0A0V0W5E2_9BILA	410	92179	Trichinella sp. T6	Innexin	Caution (2); Function (1); Sequence \
similarities (1); Subcellular location (1)
//'''.encode("utf-8"))
    return tmp_file.get_handle("r")
示例#3
0
def test_screw_formats_inplace_ui(capsys, pb_odd_resources):
    temp_file = br.TempFile()
    with open(pb_odd_resources["compare"], "r") as ifile:
        temp_file.write(ifile.read())

    test_in_args = deepcopy(in_args)
    test_in_args.screw_formats = "nexus"
    test_in_args.in_place = True
    test_in_args.trees[0] = temp_file.path

    tester = Pb.PhyloBuddy(temp_file.path)
    Pb.command_line_ui(test_in_args, tester, skip_exit=True)
    out, err = capsys.readouterr()
    assert "File overwritten at:" in err
    check_file = os.path.isfile("%s.nex" % temp_file.path)
    assert check_file

    test_in_args.trees[0] = "%s.nex" % temp_file.path
    test_in_args.screw_formats = "newick"

    tester = Pb.PhyloBuddy("%s.nex" % temp_file.path)
    Pb.command_line_ui(test_in_args, tester, skip_exit=True)
    out, err = capsys.readouterr()
    assert "File overwritten at:" in err
    check_file = os.path.isfile("%s.nwk" % temp_file.path)
    assert check_file
示例#4
0
def test_write2(alb_resources, hf, key, next_hash):
    temp_file = br.TempFile()
    alignbuddy = alb_resources.get_one(key)
    alignbuddy.write(temp_file.path, out_format="phylipr")
    with open(temp_file.path, "r", encoding="utf-8") as ifile:
        tester_hash = hf.string2hash(ifile.read())
    assert tester_hash == next_hash
示例#5
0
def test_liveshell_do_fetch(monkeypatch, capsys):
    def mock_big_record_no_dl(_dbbuddy):
        _dbbuddy.records["NP_001287575.1"] = Db.Record("NP_001287575.1",
                                                       _size=5000001)

    def mock_big_record_fetch(_dbbuddy):
        _dbbuddy.records["NP_001287575.1"].record = True

    monkeypatch.setattr(Db.LiveShell, "cmdloop", mock_cmdloop)
    monkeypatch.setattr(Db.LiveShell, "dump_session", lambda _: True)
    monkeypatch.setattr(Db, "retrieve_summary", lambda _: True)

    dbbuddy = Db.DbBuddy("NP_001287575.1")
    crash_file = br.TempFile(byte_mode=True)
    liveshell = Db.LiveShell(dbbuddy, crash_file)

    monkeypatch.setattr(Db, "retrieve_summary", mock_big_record_no_dl)
    monkeypatch.setattr(br, "ask", lambda _, **kwargs: False)

    liveshell.do_fetch("Foo")
    assert dbbuddy.records["NP_001287575.1"].size == 5000001
    out, err = capsys.readouterr()
    assert "Aborted...\n\n" in out

    monkeypatch.setattr(Db, "retrieve_sequences", mock_big_record_fetch)
    monkeypatch.setattr(br, "ask", lambda _, **kwargs: True)
    liveshell.do_fetch(None)
    out, err = capsys.readouterr()
    print(out)
    assert "Retrieved 5.0 M residues of sequence data\n\n" in out
示例#6
0
def test_liveshell_do_search(monkeypatch):
    monkeypatch.setattr(Db.LiveShell, "cmdloop", mock_cmdloop)
    monkeypatch.setattr(Db.LiveShell, "dump_session", lambda _: True)
    dbbuddy = Db.DbBuddy()
    crash_file = br.TempFile(byte_mode=True)
    liveshell = Db.LiveShell(dbbuddy, crash_file)
    dbbuddy.search_terms += ["Foo", "Bar"]

    monkeypatch.setattr("builtins.input", lambda _: "Panx1, Panx2")
    monkeypatch.setattr(Db, "retrieve_summary", lambda _: True)

    liveshell.do_search(None)
    assert dbbuddy.search_terms == ["Foo", "Bar", "Panx1", "Panx2"]
    assert not dbbuddy.records
    assert not dbbuddy.failures

    mock_buddy = Db.DbBuddy("Cx43, Cx32")
    mock_buddy.records["NewRec1"] = True
    mock_buddy.failures["NewFailure1"] = True

    monkeypatch.setattr(Db, "DbBuddy", lambda _: mock_buddy)
    liveshell.do_search("Blahh")

    assert dbbuddy.search_terms == [
        "Foo", "Bar", "Panx1", "Panx2", "Cx43", "Cx32"
    ]
    assert "NewRec1" in dbbuddy.records
    assert "NewFailure1" in dbbuddy.failures
示例#7
0
def test_delete_records_ui(capsys, alb_resources, hf):
    test_in_args = deepcopy(in_args)
    test_in_args.delete_records = ["α[1-5]", "β[A-M]"]
    Alb.command_line_ui(test_in_args, alb_resources.get_one("m d s"), skip_exit=True)
    out, err = capsys.readouterr()
    assert hf.string2hash(out) == "de5beddbc7f0a7f8e3dc2d5fd43b7b29"
    assert hf.string2hash(err) == "31bb4310333851964015e21562f602c2"

    test_in_args.delete_records = ["α[1-5]", "β[A-M]", 4]
    Alb.command_line_ui(test_in_args, alb_resources.get_one("m d s"), skip_exit=True)
    out, err = capsys.readouterr()
    assert hf.string2hash(err) == "ce6c9b29c95ba853eb444de5c71aeca9"

    test_in_args.delete_records = ["foo"]
    Alb.command_line_ui(test_in_args, alb_resources.get_one("m d s"), skip_exit=True)
    out, err = capsys.readouterr()
    assert "No sequence identifiers match 'foo'\n" in err

    tmp_file = br.TempFile()
    with open(tmp_file.path, "w", encoding="utf-8") as ofile:
        ofile.write('''\
α[1-5]
β[A-M]
''')
    test_in_args.delete_records = [tmp_file.path]
    Alb.command_line_ui(test_in_args, alb_resources.get_one("m d s"), skip_exit=True)
    out, err = capsys.readouterr()
    assert hf.string2hash(out) == "de5beddbc7f0a7f8e3dc2d5fd43b7b29"
示例#8
0
def test_instantiate_dbbuddy_from_handle():
    tmp_file = br.TempFile()
    tmp_file.write(", ".join(ACCNS))
    tmp_file.open("r")
    dbbuddy = Db.DbBuddy(tmp_file.handle)
    for accn in ACCNS:
        assert accn in dbbuddy.records
示例#9
0
def test_liveshell_postcmd(monkeypatch):
    monkeypatch.setattr(Db.LiveShell, "cmdloop", mock_cmdloop)
    dbbuddy = Db.DbBuddy()
    crash_file = br.TempFile(byte_mode=True)
    liveshell = Db.LiveShell(dbbuddy, crash_file)
    assert liveshell.postcmd("STOP!", "foo bar line") == "STOP!"
    assert liveshell.usage.stats['LiveShell'][Db.VERSION.short()]['foo'] == 1
示例#10
0
def test_liveshell_complete_load_save_write(monkeypatch):
    monkeypatch.setattr(Db.LiveShell, "cmdloop", mock_cmdloop)
    dbbuddy = Db.DbBuddy()
    crash_file = br.TempFile(byte_mode=True)
    liveshell = Db.LiveShell(dbbuddy, crash_file)
    tmpdir = br.TempDir()
    os.chdir(tmpdir.path)
    tmpdir.subfile("file.txt")
    tmpdir.subdir("extra_dir")

    # Load
    assert liveshell.complete_load("load fi ", "load fi ", 5,
                                   7) == ['file.txt']
    assert liveshell.complete_load(
        "load ", "load ", 5, 5) == ['extra_dir%s' % os.path.sep, 'file.txt']
    assert not liveshell.complete_load("load ", "load ", 4, 5)

    # Save
    assert liveshell.complete_save("save fi ", "save fi ", 5,
                                   7) == ['file.txt']
    assert liveshell.complete_save(
        "save ", "save ", 5, 5) == ['extra_dir%s' % os.path.sep, 'file.txt']
    assert not liveshell.complete_save("save ", "save ", 4, 5)

    # Save
    assert liveshell.complete_write("write fi ", "write fi ", 6,
                                    8) == ['file.txt']
    assert liveshell.complete_write(
        "write ", "write ", 6, 6) == ['extra_dir%s' % os.path.sep, 'file.txt']
    assert not liveshell.complete_write("write ", "write ", 4, 5)
示例#11
0
def test_config_values(monkeypatch):
    fake_config = br.TempFile()
    fake_config.write(
        "[DEFAULT]\nuser_hash = ABCDEFG\ndiagnostics = True\nemail = [email protected]"
        "\nshortcuts = /usr/local/sb,/usr/local/alb")
    fake_config.close()
    config_path = fake_config.path

    monkeypatch.setattr(br, "resource_filename", lambda *_: config_path)
    options = br.config_values()
    assert options["user_hash"] == "ABCDEFG"
    assert options["diagnostics"]
    assert options["email"] == "*****@*****.**"
    assert options["shortcuts"] == ['/usr/local/sb', '/usr/local/alb']

    def mock_keyerror(*args, **kwargs):
        raise KeyError(args, kwargs)

    monkeypatch.setattr(ConfigParser, "getboolean", mock_keyerror)
    monkeypatch.setattr(ConfigParser, "get", mock_keyerror)
    options = br.config_values()
    assert options["user_hash"] == "hashless"
    assert not options["diagnostics"]
    assert options["email"] == "*****@*****.**"

    def mock_distributionerror(*args, **kwargs):
        raise DistributionNotFound(args, kwargs)

    monkeypatch.setattr(br, "resource_filename", mock_distributionerror)
    options = br.config_values()
    assert not options["data_dir"]
示例#12
0
def test_liveshell_do_database(monkeypatch, capsys):
    monkeypatch.setattr(Db.LiveShell, "cmdloop", mock_cmdloop)
    monkeypatch.setattr(Db.LiveShell, "dump_session", lambda _: True)
    dbbuddy = Db.DbBuddy()
    crash_file = br.TempFile(byte_mode=True)
    liveshell = Db.LiveShell(dbbuddy, crash_file)

    liveshell.do_database("'NcBi_nuc',\t  \"ENSEMBl,uniprot")
    assert sorted(dbbuddy.databases) == ['ensembl', 'ncbi_nuc', 'uniprot']

    liveshell.do_database("ensembl,all")
    assert sorted(
        dbbuddy.databases) == ["ensembl", "ncbi_nuc", "ncbi_prot", "uniprot"]

    capsys.readouterr()
    liveshell.do_database("Foo ensembl")
    out, err = capsys.readouterr()
    assert "Invalid database choice(s): foo." in out
    assert dbbuddy.databases == ['ensembl']

    liveshell.do_database("Foo")
    out, err = capsys.readouterr()
    assert "Database search list not changed." in out
    assert dbbuddy.databases == ['ensembl']

    monkeypatch.setattr("builtins.input", lambda _: "'ncbi_nuc', 'ensembl'")
    liveshell.do_database(None)
    assert sorted(dbbuddy.databases) == ['ensembl', 'ncbi_nuc']
示例#13
0
def test_liveshell_complete_format(monkeypatch):
    monkeypatch.setattr(Db.LiveShell, "cmdloop", mock_cmdloop)
    dbbuddy = Db.DbBuddy()
    crash_file = br.TempFile(byte_mode=True)
    liveshell = Db.LiveShell(dbbuddy, crash_file)
    assert liveshell.complete_format("f") == ['full-summary', 'fasta', 'fastq', 'fastq-sanger',
                                              'fastq-solexa', 'fastq-illumina']
示例#14
0
def test_liveshell_do_load(monkeypatch, capsys, hf):
    monkeypatch.setattr(Db.LiveShell, "cmdloop", mock_cmdloop)
    monkeypatch.setattr(Db.LiveShell, "dump_session", lambda _: True)
    dbbuddy = Db.DbBuddy()
    crash_file = br.TempFile(byte_mode=True)
    liveshell = Db.LiveShell(dbbuddy, crash_file)
    dbbuddy.server_clients["uniprot"] = Db.UniProtRestClient(dbbuddy)
    dbbuddy.server_clients["uniprot"].http_errors_file.write("Hello!")

    db_session = "%s/mock_resources/test_databasebuddy_clients/dbbuddy_save.db" % hf.resource_path
    monkeypatch.setattr("builtins.input", lambda _: db_session)
    liveshell.do_load(None)
    out, err = capsys.readouterr()
    assert "Session loaded from file.\n\n" in out

    assert dbbuddy.server_clients["uniprot"].http_errors_file.read() == ""
    headings = liveshell.get_headings()
    for heading in ['ACCN', 'DB', 'Type', 'record', 'entry_name', 'length', 'organism-id', 'organism',
                    'protein_names', 'comments', 'gi_num', 'TaxId', 'status', 'name', 'biotype',
                    'object_type', 'strand', 'assembly_name', 'name']:
        assert heading in headings

    for heading in headings:
        assert heading in ['ACCN', 'DB', 'Type', 'record', 'entry_name', 'length', 'organism-id', 'organism',
                           'protein_names', 'comments', 'gi_num', 'TaxId', 'status', 'name', 'biotype',
                           'object_type', 'strand', 'assembly_name', 'name']

    monkeypatch.setattr("builtins.input", lambda _: "/no/file/here")
    liveshell.do_load(None)
    out, err = capsys.readouterr()
    assert "Error: Unable to read the provided file. Are you sure it's a saved DbBuddy live session?\n\n" in out
示例#15
0
def test_liveshell_do_write(monkeypatch, capsys, hf):
    monkeypatch.setattr(Db.LiveShell, "cmdloop", mock_cmdloop)
    monkeypatch.setattr(Db.LiveShell, "dump_session", lambda _: True)
    dbbuddy = Db.DbBuddy()
    crash_file = br.TempFile(byte_mode=True)
    liveshell = Db.LiveShell(dbbuddy, crash_file)

    load_file = "%s/mock_resources/test_databasebuddy_clients/dbbuddy_save.db" % hf.resource_path
    liveshell.do_load(load_file)
    capsys.readouterr()
    tmp_dir = br.TempDir()

    # write a summary
    monkeypatch.setattr("builtins.input", lambda _: "%s/save1" % tmp_dir.path)
    liveshell.do_write(None)
    assert os.path.isfile("%s/save1" % tmp_dir.path)
    with open("%s/save1" % tmp_dir.path, "r") as ifile:
        assert len(ifile.read()) == 249980
    out, err = capsys.readouterr()
    assert re.search("1407 summary records.*written to.*save1", out)

    # write ids/accns
    dbbuddy.out_format = "ids"
    monkeypatch.setattr(br, "ask", lambda _: True)
    dbbuddy.records['O14727'].record = Db.Record('O14727', _record=True)
    liveshell.do_write("%s/save2" % tmp_dir.path)
    assert os.path.isfile("%s/save2" % tmp_dir.path)
    with open("%s/save2" % tmp_dir.path, "r") as ifile:
        assert len(ifile.read()) == 18661
    out, err = capsys.readouterr()
    assert re.search("1407 accessions.*written to.*save2", out)

    # Abort summary
    monkeypatch.setattr(br, "ask", lambda _: False)
    liveshell.do_write("%s/save3" % tmp_dir.path)
    assert not os.path.isfile("%s/save3" % tmp_dir.path)
    out, err = capsys.readouterr()
    assert "Abort..." in out

    # Permission error
    dbbuddy.out_format = "fasta"
    monkeypatch.setattr("builtins.open", OpenPermissionError)
    liveshell.do_write("%s/save4" % tmp_dir.path)
    assert not os.path.isfile("%s/save4" % tmp_dir.path)
    out, err = capsys.readouterr()
    assert "Error: You do not have write privileges in the specified directory.\n\n" in out

    # File exists
    monkeypatch.setattr(br, "ask", lambda _: False)
    liveshell.do_write("%s/save2" % tmp_dir.path)
    out, err = capsys.readouterr()
    assert "Abort..." in out
    assert "written" not in out

    # Not a directory
    liveshell.do_write("%s/ghostdir/save5" % tmp_dir.path)
    out, err = capsys.readouterr()
    assert "The specified directory does not exist. Please create it before continuing" in out
    assert "written" not in out
示例#16
0
def mock_urlopen_handle_uniprot_ids(*args, **kwargs):
    print("mock_urlopen_handle_uniprot_ids\nargs: %s\nkwargs: %s" % (args, kwargs))
    tmp_file = br.TempFile(byte_mode=True)
    tmp_file.write('''A8XEF9
O61786
A0A0H5SBJ0
'''.encode("utf-8"))
    return tmp_file.get_handle("r")
示例#17
0
def test_liveshell_complete_database(monkeypatch):
    monkeypatch.setattr(Db.LiveShell, "cmdloop", mock_cmdloop)
    dbbuddy = Db.DbBuddy()
    crash_file = br.TempFile(byte_mode=True)
    liveshell = Db.LiveShell(dbbuddy, crash_file)
    assert sorted(liveshell.complete_database("")) == [
        'ensembl', 'ncbi_nuc', 'ncbi_prot', 'uniprot'
    ]
示例#18
0
def test_liveshell_get_headings(monkeypatch):
    monkeypatch.setattr(Db.LiveShell, "cmdloop", mock_cmdloop)
    monkeypatch.setattr(Db, "retrieve_summary", lambda _: True)
    dbbuddy = Db.DbBuddy(",".join(ACCNS))
    crash_file = br.TempFile(byte_mode=True)
    liveshell = Db.LiveShell(dbbuddy, crash_file)
    dbbuddy.records['XM_003978475'].summary = {'organism': 'velociraptor'}
    assert liveshell.get_headings() == ['ACCN', 'DB', 'Type', 'record', 'organism']
示例#19
0
def test_liveshell_complete_delete(monkeypatch):
    monkeypatch.setattr(Db.LiveShell, "cmdloop", mock_cmdloop)
    dbbuddy = Db.DbBuddy()
    crash_file = br.TempFile(byte_mode=True)
    liveshell = Db.LiveShell(dbbuddy, crash_file)
    assert liveshell.complete_delete("") == [
        "all", "failures", "search", "trash", "records"
    ]
def test_write1(alb_resources, hf, key, next_hash):
    temp_file = br.TempFile()
    alignbuddy = alb_resources.get_one(key)
    alignbuddy.write(temp_file.path)
    with open(temp_file.path, "r", encoding="utf-8") as ifile:
        output = ifile.read()
        tester_hash = hf.string2hash(output)
    assert tester_hash == next_hash
示例#21
0
def test_liveshell_do_restore(monkeypatch, capsys):
    monkeypatch.setattr(Db.LiveShell, "cmdloop", mock_cmdloop)
    dbbuddy = Db.DbBuddy()
    crash_file = br.TempFile(byte_mode=True)
    liveshell = Db.LiveShell(dbbuddy, crash_file)
    monkeypatch.setattr(Db.LiveShell, "filter", mock_filter)
    liveshell.do_restore(None)
    out, err = capsys.readouterr()
    assert "'restore' filter mocked! None" in out
示例#22
0
 def patch_ensembl_perform_rest_action(*args, **kwargs):
     print("patch_ensembl_perform_rest_action\nargs: %s\nkwargs: %s" % (args, kwargs))
     if "info/species" in args:
         with open("%s/ensembl_species.json" % test_files, "r") as ifile:
             return json.load(ifile)
     elif "sequence/id" in args:
         with open("%s/ensembl_sequence.seqxml" % test_files, "r") as ifile:
             tmp_file = br.TempFile(byte_mode=True)
             tmp_file.write(ifile.read().encode())
             return Db.SeqIO.parse(tmp_file.get_handle("r"), "seqxml")
示例#23
0
def test_liveshell_complete_bash(monkeypatch):
    # Note, this doesn't work in Windows
    if os.name == "nt":
        return
    monkeypatch.setattr(Db.LiveShell, "cmdloop", mock_cmdloop)
    dbbuddy = Db.DbBuddy()
    crash_file = br.TempFile(byte_mode=True)
    liveshell = Db.LiveShell(dbbuddy, crash_file)
    programs = liveshell.complete_bash("wh")
    for program in ['wheel ', 'whereis ', 'whoami ', 'which ', 'who ']:
        assert program in programs
示例#24
0
def test_liveshell_do_trash(monkeypatch, capsys):
    def mock_show(_, line, mode):
        print("%s show mocked! %s" % (mode, line))
        return

    monkeypatch.setattr(Db.LiveShell, "cmdloop", mock_cmdloop)
    dbbuddy = Db.DbBuddy()
    crash_file = br.TempFile(byte_mode=True)
    liveshell = Db.LiveShell(dbbuddy, crash_file)
    monkeypatch.setattr(Db.LiveShell, "do_show", mock_show)
    liveshell.do_trash(None)
    out, err = capsys.readouterr()
    assert "trash_bin show mocked! None" in out
示例#25
0
def test_liveshell_default(monkeypatch, capsys):
    monkeypatch.setattr(Db.LiveShell, "cmdloop", mock_cmdloop)
    dbbuddy = Db.DbBuddy()
    crash_file = br.TempFile(byte_mode=True)
    liveshell = Db.LiveShell(dbbuddy, crash_file)
    liveshell.default("Dunno...")
    out, err = capsys.readouterr()
    assert '*** Unknown syntax: Dunno...\n\n' in out

    with pytest.raises(SystemExit):
        liveshell.default("exit")
    out, err = capsys.readouterr()
    assert "Goodbye" in out
示例#26
0
def mock_urlopen_uniprot_count_hits(*args, **kwargs):
    print("mock_urlopen_uniprot_count_hits\nargs: %s\nkwargs: %s" % (args, kwargs))
    tmp_file = br.TempFile(byte_mode=True)
    tmp_file.write('''# Search: (inx15)+OR+(inx16)
O61787
A0A0V1AZ11
A8XEF9
A8XEF8
A0A0B2VB60
A0A0V0W5E2
O61786
A0A0H5SBJ0
E3MGD6
E3MGD5
//'''.encode("utf-8"))
    return tmp_file.get_handle("r")
示例#27
0
    def patch_entrez_esearch(*args, **kwargs):
        print("patch_entrez_esearch\nargs: %s\nkwargs: %s" % (args, kwargs))
        if "rettype" in kwargs:
            test_file = br.TempFile()
            test_file.write("""<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE eSearchResult PUBLIC "-//NLM//DTD esearch 20060628//EN" \
"http://eutils.ncbi.nlm.nih.gov/eutils/dtd/20060628/esearch.dtd">
<eSearchResult>
    <Count>5</Count>
</eSearchResult>
""")
            handle = test_file.get_handle(mode="r")
        else:
            handle = open("%s/mock_resources/test_databasebuddy_clients/Entrez_esearch.xml" % hf.resource_path,
                          "r")
        return handle
示例#28
0
def test_liveshell_do_failures(monkeypatch, capsys):
    monkeypatch.setattr(Db.LiveShell, "cmdloop", mock_cmdloop)
    monkeypatch.setattr(Db.LiveShell, "dump_session", lambda _: True)
    dbbuddy = Db.DbBuddy()
    crash_file = br.TempFile(byte_mode=True)
    liveshell = Db.LiveShell(dbbuddy, crash_file)

    liveshell.do_failures("Blahh")
    out, err = capsys.readouterr()
    assert "No failures to report\n\n" in out

    dbbuddy.failures["Foo"] = Db.Failure("Bar", "Fake failure")
    liveshell.do_failures()
    out, err = capsys.readouterr()
    assert "The following failures have occured\n" in out
    assert "Bar\nFake failure" in out
示例#29
0
def test_liveshell_dump_session(monkeypatch):
    monkeypatch.setattr(Db.LiveShell, "cmdloop", mock_cmdloop)
    dbbuddy = Db.DbBuddy(_databases="uniprot")
    dbbuddy.server_clients["uniprot"] = Db.UniProtRestClient(dbbuddy)
    crash_file = br.TempFile(byte_mode=True)
    liveshell = Db.LiveShell(dbbuddy, crash_file)
    pre_dump = liveshell.crash_file.read()
    liveshell.dump_session()
    assert pre_dump == liveshell.crash_file.read()

    liveshell.dbbuddy.search_terms.append("Blahh")
    liveshell.dump_session()
    assert pre_dump != liveshell.crash_file.read()

    assert liveshell.dbbuddy.server_clients['uniprot'].lock
    assert not liveshell.dbbuddy.server_clients['ensembl']
    assert liveshell.undo
示例#30
0
def test_liveshell_do_quit(monkeypatch, capsys):
    monkeypatch.setattr(Db.LiveShell, "cmdloop", mock_cmdloop)
    monkeypatch.setattr(Db.LiveShell, "dump_session", lambda _: True)
    dbbuddy = Db.DbBuddy()
    crash_file = br.TempFile(byte_mode=True)
    liveshell = Db.LiveShell(dbbuddy, crash_file)

    dbbuddy.records["Foo"] = "Bar"
    monkeypatch.setattr(br, "ask", lambda _, **kwargs: False)
    liveshell.do_quit(None)
    out, err = capsys.readouterr()
    assert "Aborted...\n\n" in out

    with pytest.raises(SystemExit):
        monkeypatch.setattr(br, "ask", lambda _, **kwargs: True)
        liveshell.do_quit(None)
    out, err = capsys.readouterr()
    assert "Goodbye" in out