Exemple #1
0
 def test_load_section_schema_error(self):
     section_name = uuid.uuid4().hex
     fake_default_key = uuid.uuid4().hex
     fake_defaults = {fake_default_key:4}
     assert_helper.assertRaises(
             ValidationError, BaseConfig().load_section,
             section_name, fake_defaults, {fake_default_key:{"type":"boolean"}})
def test_case05():
    if version < "7.0":
        args, msg = parse_cmd_args(g)
        result = vars(args)
        assert result['port'] == 4242 and result['serverPort'] == 9084
    else:
        with assert_helper.assertRaises(SystemExit):
            args, msg = parse_cmd_args(g)
def test_case04():
    if version < "7.0":
        args, msg = parse_cmd_args(g)
        result = vars(args)
        assert isinstance(result['port'], int)
        assert result['port'] == 4242
    else:
        with assert_helper.assertRaises(SystemExit):
            args, msg = parse_cmd_args(g)
Exemple #4
0
def test_swq_access():
    """Access to sequence object members"""
    read = "ACTGGGTGTAT"
    read2 = "TATGTGGGTCA"
    qual = "IIIIIIIIIII"
    qual2 = "DDDDDDDDDDD"
    name = 'test'
    seq = SequenceWithQuality(read, qual, name)
    assert seq[0] == ('A', 'I'), "Failed to extract sequence/quality pair"
    seq.sequence = read2
    assert seq.sequence == read2, "Failed to change read sequence"
    seq.quality = qual2
    assert seq.quality == qual2, "Failed to change qualities"

    ## check that attempts to set members to new values that
    ## would result in an inconsistent state raise an exception
    with helper.assertRaises(ValueError):
        SequenceWithQuality("ACTG", qual)
    with helper.assertRaises(ValueError):
        seq.sequence = "ACTG"
    with helper.assertRaises(ValueError):
        SequenceWithQuality(read, "!!!!")
    with helper.assertRaises(ValueError):
        seq.quality = "!!!!!"
Exemple #5
0
def test_grouped_remove():
    """Remove sequences from GroupedSequenceStore"""
    store = GroupedSequenceStore(4, tag_size=2)
    store.add("AAAA")
    store.add("CTGT")
    assert "AAAA" in store, "'AAAA' not found in store"
    assert "CTGT" in store, "'CTGT' not found in store"
    store.remove("AAAA")
    assert "AAAA" not in store, "'AAAA' remains in store after removal"
    with helper.assertRaises(KeyError):
        store.remove("AAAA")
    assert "CTGT" in store, "'CTGT' not found in store"
    assert len(store) == 1, "%r != 1" % len(store)
    store.remove("CTGT")
    assert "CTGT" not in store, "'CTGT' remains in store after removal"
    assert len(store) == 0, "%r != 0" % len(store)
Exemple #6
0
def test_full_exchange():
    # Find an open port
    for port in range(40000, 50000):
        with closing(socket.socket(socket.AF_INET,
                                   socket.SOCK_STREAM)) as sock:
            if sock.connect_ex(('localhost', port)) != 0:
                break

    pid = os.fork()
    if pid == 0:
        rsa_ct_kip.fakeserver.app.config[
            'auth'] = '12345'  # Required auth code
        rsa_ct_kip.fakeserver.app.run(host='localhost',
                                      port=port,
                                      debug=True,
                                      use_reloader=False,
                                      ssl_context=None)
        os._exit(0)

    try:
        # Wait for server to become ready
        with closing(socket.socket(socket.AF_INET,
                                   socket.SOCK_STREAM)) as sock:
            if sock.connect_ex(('localhost', port)) != 0:
                time.sleep(1)

        # Test with bad/wrong auth code
        with helper.assertRaises(RuntimeError):
            rsa_ct_kip.client.exchange('http://localhost:{}'.format(port),
                                       '67890')

        # Test with correct auth code
        token = rsa_ct_kip.client.exchange('http://localhost:{}'.format(port),
                                           '12345')
        assert isinstance(token.get('K_TOKEN'), bytes)
    finally:
        os.kill(pid, signal.SIGTERM)
Exemple #7
0
def test_case01():
    with assert_helper.assertRaises(TypeError):
        configureLogging()
Exemple #8
0
def test_case03():
    with assert_helper.assertRaises(TypeError):
        configureLogging(None, 'myLog')
Exemple #9
0
def test_init_with_negative_quantity():
    with helper.assertRaises(ValueError):
        create_item(-1)
Exemple #10
0
def test_init_with_zero_quantity():
    with helper.assertRaises(ValueError):
        create_item(0)
def test_init_with_negative_quantity():
    with helper.assertRaises(ValueError):
        create_item(-1)
def test_init_with_zero_quantity():
    with helper.assertRaises(ValueError):
        create_item(0)
Exemple #13
0
 def test_get_config_dir(self):
     assert_helper.assertRaises(NotImplementedError, BaseConfig().get_config_dir)
     with mock.patch("turf.config.BaseConfig.config_dir", new=mock.PropertyMock(
             return_value = "fake_config_dir")) as config_dir_mock:
         assert BaseConfig().get_config_dir() == "fake_config_dir"
Exemple #14
0
def test_findCards():
    deck = getEmptyCol()
    f = deck.newNote()
    f["Front"] = "dog"
    f["Back"] = "cat"
    f.tags.append("monkey animal_1 * %")
    f1id = f.id
    deck.addNote(f)
    firstCardId = f.cards()[0].id
    f = deck.newNote()
    f["Front"] = "goats are fun"
    f["Back"] = "sheep"
    f.tags.append("sheep goat horse animal11")
    deck.addNote(f)
    f2id = f.id
    f = deck.newNote()
    f["Front"] = "cat"
    f["Back"] = "sheep"
    deck.addNote(f)
    catCard = f.cards()[0]
    m = deck.models.current()
    mm = deck.models
    t = mm.newTemplate("Reverse")
    t["qfmt"] = "{{Back}}"
    t["afmt"] = "{{Front}}"
    mm.addTemplate(m, t)
    mm.save(m)
    f = deck.newNote()
    f["Front"] = "test"
    f["Back"] = "foo bar"
    deck.addNote(f)
    latestCardIds = [c.id for c in f.cards()]
    # tag searches
    assert len(deck.findCards("tag:*")) == 5
    assert len(deck.findCards("tag:\\*")) == 1
    assert len(deck.findCards("tag:%")) == 5
    assert len(deck.findCards("tag:\\%")) == 1
    assert len(deck.findCards("tag:animal_1")) == 2
    assert len(deck.findCards("tag:animal\\_1")) == 1
    assert not deck.findCards("tag:donkey")
    assert len(deck.findCards("tag:sheep")) == 1
    assert len(deck.findCards("tag:sheep tag:goat")) == 1
    assert len(deck.findCards("tag:sheep tag:monkey")) == 0
    assert len(deck.findCards("tag:monkey")) == 1
    assert len(deck.findCards("tag:sheep -tag:monkey")) == 1
    assert len(deck.findCards("-tag:sheep")) == 4
    deck.tags.bulkAdd(deck.db.list("select id from notes"), "foo bar")
    assert len(deck.findCards("tag:foo")) == len(
        deck.findCards("tag:bar")) == 5
    deck.tags.bulkRem(deck.db.list("select id from notes"), "foo")
    assert len(deck.findCards("tag:foo")) == 0
    assert len(deck.findCards("tag:bar")) == 5
    # text searches
    assert len(deck.findCards("cat")) == 2
    assert len(deck.findCards("cat -dog")) == 1
    assert len(deck.findCards("cat -dog")) == 1
    assert len(deck.findCards("are goats")) == 1
    assert len(deck.findCards('"are goats"')) == 0
    assert len(deck.findCards('"goats are"')) == 1
    # card states
    c = f.cards()[0]
    c.queue = c.type = 2
    assert deck.findCards("is:review") == []
    c.flush()
    assert deck.findCards("is:review") == [c.id]
    assert deck.findCards("is:due") == []
    c.due = 0
    c.queue = 2
    c.flush()
    assert deck.findCards("is:due") == [c.id]
    assert len(deck.findCards("-is:due")) == 4
    c.queue = -1
    # ensure this card gets a later mod time
    c.flush()
    deck.db.execute("update cards set mod = mod + 1 where id = ?", c.id)
    assert deck.findCards("is:suspended") == [c.id]
    # nids
    assert deck.findCards("nid:54321") == []
    assert len(deck.findCards("nid:%d" % f.id)) == 2
    assert len(deck.findCards("nid:%d,%d" % (f1id, f2id))) == 2
    # templates
    with helper.assertRaises(Exception):
        deck.findCards("card:foo")
    assert len(deck.findCards("'card:card 1'")) == 4
    assert len(deck.findCards("card:reverse")) == 1
    assert len(deck.findCards("card:1")) == 4
    assert len(deck.findCards("card:2")) == 1
    # fields
    assert len(deck.findCards("front:dog")) == 1
    assert len(deck.findCards("-front:dog")) == 4
    assert len(deck.findCards("front:sheep")) == 0
    assert len(deck.findCards("back:sheep")) == 2
    assert len(deck.findCards("-back:sheep")) == 3
    assert len(deck.findCards("front:do")) == 0
    assert len(deck.findCards("front:*")) == 5
    # ordering
    deck.conf["sortType"] = "noteCrt"
    assert deck.findCards("front:*", order=True)[-1] in latestCardIds
    assert deck.findCards("", order=True)[-1] in latestCardIds
    deck.conf["sortType"] = "noteFld"
    assert deck.findCards("", order=True)[0] == catCard.id
    assert deck.findCards("", order=True)[-1] in latestCardIds
    deck.conf["sortType"] = "cardMod"
    assert deck.findCards("", order=True)[-1] in latestCardIds
    assert deck.findCards("", order=True)[0] == firstCardId
    deck.conf["sortBackwards"] = True
    assert deck.findCards("", order=True)[0] in latestCardIds
    # model
    assert len(deck.findCards("note:basic")) == 5
    assert len(deck.findCards("-note:basic")) == 0
    assert len(deck.findCards("-note:foo")) == 5
    # deck
    assert len(deck.findCards("deck:default")) == 5
    assert len(deck.findCards("-deck:default")) == 0
    assert len(deck.findCards("-deck:foo")) == 5
    assert len(deck.findCards("deck:def*")) == 5
    assert len(deck.findCards("deck:*EFAULT")) == 5
    with helper.assertRaises(Exception):
        deck.findCards("deck:*cefault")
    # full search
    f = deck.newNote()
    f["Front"] = "hello<b>world</b>"
    f["Back"] = "abc"
    deck.addNote(f)
    # as it's the sort field, it matches
    assert len(deck.findCards("helloworld")) == 2
    # assert len(deck.findCards("helloworld", full=True)) == 2
    # if we put it on the back, it won't
    (f["Front"], f["Back"]) = (f["Back"], f["Front"])
    f.flush()
    assert len(deck.findCards("helloworld")) == 0
    # assert len(deck.findCards("helloworld", full=True)) == 2
    # assert len(deck.findCards("back:helloworld", full=True)) == 2
    # searching for an invalid special tag should not error
    with helper.assertRaises(Exception):
        len(deck.findCards("is:invalid"))
    # should be able to limit to parent deck, no children
    id = deck.db.scalar("select id from cards limit 1")
    deck.db.execute("update cards set did = ? where id = ?",
                    deck.decks.id("Default::Child"), id)
    assert len(deck.findCards("deck:default")) == 7
    assert len(deck.findCards("deck:default::child")) == 1
    assert len(deck.findCards("deck:default -deck:default::*")) == 6
    # properties
    id = deck.db.scalar("select id from cards limit 1")
    deck.db.execute(
        "update cards set queue=2, ivl=10, reps=20, due=30, factor=2200 "
        "where id = ?",
        id,
    )
    assert len(deck.findCards("prop:ivl>5")) == 1
    assert len(deck.findCards("prop:ivl<5")) > 1
    assert len(deck.findCards("prop:ivl>=5")) == 1
    assert len(deck.findCards("prop:ivl=9")) == 0
    assert len(deck.findCards("prop:ivl=10")) == 1
    assert len(deck.findCards("prop:ivl!=10")) > 1
    assert len(deck.findCards("prop:due>0")) == 1
    # due dates should work
    deck.sched.today = 15
    assert len(deck.findCards("prop:due=14")) == 0
    assert len(deck.findCards("prop:due=15")) == 1
    assert len(deck.findCards("prop:due=16")) == 0
    # including negatives
    deck.sched.today = 32
    assert len(deck.findCards("prop:due=-1")) == 0
    assert len(deck.findCards("prop:due=-2")) == 1
    # ease factors
    assert len(deck.findCards("prop:ease=2.3")) == 0
    assert len(deck.findCards("prop:ease=2.2")) == 1
    assert len(deck.findCards("prop:ease>2")) == 1
    assert len(deck.findCards("-prop:ease>2")) > 1
    # recently failed
    assert len(deck.findCards("rated:1:1")) == 0
    assert len(deck.findCards("rated:1:2")) == 0
    c = deck.sched.getCard()
    deck.sched.answerCard(c, 2)
    assert len(deck.findCards("rated:1:1")) == 0
    assert len(deck.findCards("rated:1:2")) == 1
    c = deck.sched.getCard()
    deck.sched.answerCard(c, 1)
    assert len(deck.findCards("rated:1:1")) == 1
    assert len(deck.findCards("rated:1:2")) == 1
    assert len(deck.findCards("rated:1")) == 2
    assert len(deck.findCards("rated:0:2")) == 0
    assert len(deck.findCards("rated:2:2")) == 1
    # empty field
    assert len(deck.findCards("front:")) == 0
    f = deck.newNote()
    f["Front"] = ""
    f["Back"] = "abc2"
    assert deck.addNote(f) == 1
    assert len(deck.findCards("front:")) == 1
    # OR searches and nesting
    assert len(deck.findCards("tag:monkey or tag:sheep")) == 2
    assert len(deck.findCards("(tag:monkey OR tag:sheep)")) == 2
    assert len(deck.findCards("-(tag:monkey OR tag:sheep)")) == 6
    assert len(deck.findCards("tag:monkey or (tag:sheep sheep)")) == 2
    assert len(deck.findCards("tag:monkey or (tag:sheep octopus)")) == 1
    # invalid grouping shouldn't error
    assert len(deck.findCards(")")) == 0
    assert len(deck.findCards("(()")) == 0
    # added
    assert len(deck.findCards("added:0")) == 0
    deck.db.execute("update cards set id = id - 86400*1000 where id = ?", id)
    assert len(deck.findCards("added:1")) == deck.cardCount() - 1
    assert len(deck.findCards("added:2")) == deck.cardCount()
    # flag
    with helper.assertRaises(Exception):
        deck.findCards("flag:01")
    with helper.assertRaises(Exception):
        deck.findCards("flag:12")