示例#1
0
def test_show_entries0001(jrnl):  # noqa: F811
    """Check normal output works"""

    dt = datetime.datetime(2017, 1, 1, 12, 00, 00)
    insert_entry(jrnl,
                 "My Title",
                 "@tag1 @tag2",
                 "Body",
                 time=dt,
                 fn_suffix="xxxxxxxx")
    out, err, rv = run_j(jrnl, [])
    assert rv == 0
    assert err.strip() == b""
    lines = out.strip().splitlines()
    assert len(lines) == 6

    assert lines[0] == \
        b'=========================================================' \
        b'====================='

    assert lines[1] == \
        b'2017-01-01 12:00:00                                   ' \
        b'20170101_120000-xxxxxxxx'

    assert lines[2].strip() == b'My Title'
    assert lines[3].strip() == b'@tag1 @tag2' or \
        lines[3].strip() == b'@tag2 @tag1'
    assert lines[4] == b''
    assert lines[5] == b'Body'
示例#2
0
def test_textual_filter_0004(jrnl, filters):  # noqa: F811
    """Check textual search is not case sensitive by default"""

    insert_entry(jrnl, title="About the BBQ", body="Toxic BBQ")
    filters.textual_filters = ["toxic"]
    ents = jrnl._collect_entries(filters)
    assert len(ents) == 1
示例#3
0
def test_textual_filter_0005(jrnl, filters):  # noqa: F811
    """Check case sensitive textual search"""

    filters.case_sensitive = True
    insert_entry(jrnl, title="About the BBQ", body="Toxic BBQ")
    filters.textual_filters = ["toxic"]
    ents = jrnl._collect_entries(filters)
    assert len(ents) == 0
示例#4
0
def test_collect_0003(jrnl):  # noqa: F811
    """Check adding many entries works"""

    for i in range(128):
        insert_entry(jrnl, title="hello%s" % i)
        ents = jrnl._collect_entries()

    assert len(ents) == 128
示例#5
0
def test_textual_filter_0002(jrnl, filters):  # noqa: F811
    """Check search of entry title works"""

    insert_entry(jrnl, title="About the BBQ", body="Toxic BBQ")
    insert_entry(jrnl, title="Crew", body="Kryten, Lister, Cat, Rimmer")

    filters.textual_filters = ["Crew"]
    ents = jrnl._collect_entries(filters)
    assert len(ents) == 1
    assert ents[0].title == "Crew"
示例#6
0
def test_time_filter0003(jrnl, now):  # noqa: F811
    """Test relative end time"""

    filters = FilterSettings(time_filter=TimeFilter.from_arg(":1d"))
    path1 = insert_entry(jrnl, title="old", time=now - timedelta(days=3))
    insert_entry(jrnl, title="new")
    ents = jrnl._collect_entries(filters)

    assert len(ents) == 1
    assert ents[0].path == path1
示例#7
0
def test_time_filter0006(jrnl, now):  # noqa: F811
    """Test absolute end time"""

    tstr = (now - timedelta(days=1)).strftime(":%Y-%m-%d")
    filters = FilterSettings(time_filter=TimeFilter.from_arg(tstr))
    path1 = insert_entry(jrnl, title="old", time=now - timedelta(days=3))
    insert_entry(jrnl, title="new")
    ents = jrnl._collect_entries(filters)

    assert len(ents) == 1
    assert ents[0].path == path1
示例#8
0
def test_textual_filter_0003(jrnl, filters):  # noqa: F811
    """Check multiple hits"""

    for i in range(20):
        insert_entry(jrnl, title="title%s" % i, body="test")

    filters.textual_filters = ["5"]
    ents = jrnl._collect_entries(filters)
    assert len(ents) == 2
    assert ents[0].title == "title5"
    assert ents[1].title == "title15"
示例#9
0
def test_time_filter0008(jrnl, now):  # noqa: F811
    """Test absolute start and end time"""

    tstr1 = (now - timedelta(days=2)).strftime("%Y-%m-%d")
    tstr2 = (now - timedelta(days=1)).strftime("%Y-%m-%d")
    tstr = "%s:%s" % (tstr1, tstr2)
    filters = FilterSettings(time_filter=TimeFilter.from_arg(tstr))
    insert_entry(jrnl, title="old", time=now - timedelta(days=5))
    path2 = insert_entry(jrnl, title="new", time=now - timedelta(days=2))
    insert_entry(jrnl, title="newer", time=now + timedelta(days=5))
    ents = jrnl._collect_entries(filters)

    assert len(ents) == 1
    assert ents[0].path == path2
示例#10
0
def test_parse_entry_0007(jrnl):  # noqa: F811
    """Check an entry with invalid and valid attrs fails to parse"""

    path = insert_entry(jrnl, title="title", attrs="@ok @also-ok bad")
    with pytest.raises(j.ParseError) as e:
        Entry(path)
    assert "unknown attribute" in str(e)
示例#11
0
def test_parse_entry_0006(jrnl):  # noqa: F811
    """Check an entry with a single invalid attr fails to parse"""

    path = insert_entry(jrnl, title="title", attrs="zzz")
    with pytest.raises(j.ParseError) as e:
        Entry(path)
    assert "unknown attribute" in str(e)
示例#12
0
def test_parse_entry_0003(jrnl):  # noqa: F811
    """Check an entry with no title fails to parse gracefully"""

    path = insert_entry(jrnl, title="")
    with pytest.raises(j.ParseError) as e:
        Entry(path)
    assert "whitespace title" in str(e)
示例#13
0
def test_parse_entry_0009(jrnl):  # noqa: F811
    """Check an entry with unicode doesn't explode"""

    path = insert_entry(jrnl, title="τοῦ", attrs="@Конф", body="สิบสอง")
    ent = Entry(path)
    assert ent.title == "τοῦ"
    assert ent.tags == {"Конф"}
    assert ent.body == "สิบสอง"
示例#14
0
def test_parse_entry_0010(jrnl):  # noqa: F811
    """Check an entry with multiple tags works"""

    path = insert_entry(jrnl, title="title", attrs="@t1 @t2 @t3")
    ent = Entry(path)
    assert ent.title == "title"
    assert ent.tags == {"t1", "t2", "t3"}
    assert ent.body is None
示例#15
0
def test_parse_entry_0008(jrnl):  # noqa: F811
    """Check an entry with no body parses OK"""

    path = insert_entry(jrnl, title="title", attrs="@tag")
    ent = Entry(path)
    assert ent.title == "title"
    assert ent.tags == {"tag"}
    assert ent.body is None
示例#16
0
def test_parse_entry_0001(jrnl):  # noqa: F811
    """Check a typical entry parses"""

    path = insert_entry(jrnl, title="title", attrs="@tag", body="body\nbody")
    ent = Entry(path)

    assert ent.title == "title"
    assert ent.tags == {"tag"}
    assert ent.body == "body\nbody"
示例#17
0
def test_parse_entry_0004(jrnl):  # noqa: F811
    """Check a title only entry parses"""

    path = insert_entry(jrnl, title="title")
    ent = Entry(path)

    assert ent.title == "title"
    assert ent.tags == set()
    assert ent.body is None
示例#18
0
def test_parse_entry_0005(jrnl):  # noqa: F811
    """Check an entry with no attributes parses"""

    path = insert_entry(jrnl, title="title", body="123\n456")
    ent = Entry(path)

    assert ent.title == "title"
    assert ent.tags == set()
    assert ent.body == "123\n456"
示例#19
0
def test_show_entries0002(jrnl):  # noqa: F811
    """Check normal output works"""

    dt = datetime.datetime(2017, 1, 1, 12, 00, 00)
    insert_entry(jrnl,
                 "My Title",
                 "@tag1 @tag2",
                 "Body",
                 time=dt,
                 fn_suffix="xxxxxxxx")
    out, err, rv = run_j(jrnl, ["s", "-j"])
    assert rv == 0
    assert err.strip() == b""
    jsn = json.loads(out.strip())
    assert len(jsn["entries"]) == 1
    ent = jsn["entries"][0]

    assert ent["title"] == "My Title"
    assert ent["time"] == "2017-01-01 12:00:00"
    assert set(ent["tags"]) == set(["tag1", "tag2"])
示例#20
0
def test_time_filter0009(jrnl, now):  # noqa: F811
    """Checks that a immortal entry unconditionally passes the time filter"""

    tstr = (now - timedelta(days=2)).strftime("%Y-%m-%d")
    filters = FilterSettings(time_filter=TimeFilter.from_arg(tstr))
    path = insert_entry(jrnl,
                        title="old_immortal",
                        time=now - timedelta(days=500 * 365),
                        attrs="immortal")

    ents = jrnl._collect_entries(filters)
    assert len(ents) == 1
    assert ents[0].path == path
示例#21
0
def test_time_filter0001(jrnl):  # noqa: F811
    """Test ':' is unrestricted"""

    filters = FilterSettings(time_filter=TimeFilter.from_arg(":"))
    insert_entry(jrnl, title="hello1", time=datetime.datetime.min)
    insert_entry(jrnl, title="hello2", time=datetime.datetime.max)
    insert_entry(jrnl, title="hello3")
    ents = jrnl._collect_entries(filters=filters)

    assert len(ents) == 3
示例#22
0
def test_collect_0002(jrnl):  # noqa: F811
    """Check adding a title-only entry is OK"""

    insert_entry(jrnl, title="hello")
    ents = jrnl._collect_entries()
    assert len(ents) == 1