예제 #1
0
def test_not_reminder_exists(capsys, move_reminders):
    """Requesting a nonexistant reminder should raise an error."""
    clean_reminders()
    with raises(ValueError) as error:
        run_args(
            parse_args(['show', 'reminder'],
                       parser_class=ErrorRaisingArgumentParser))
    assert "is not a reminder" in str(error)
예제 #2
0
def test_read_same_as_passed(move_reminders, reminder_text):
    """Test that the value passed to a reminder is the value read from a reminder."""
    clean_reminders()
    assume(not reminder_text.startswith('-'))

    parsed = parse_args(['add', reminder_text])
    run_args(parsed)
    with parsed.fpath.open('r') as reminder_file:
        assert reminder_file.read() == reminder_text
        assert get_reminder(parsed.fpath) == reminder_text
예제 #3
0
def test_subprocess_opens_vim(move_reminders):
    """Test that edit works as expected."""
    clean_reminders()
    namespace = parse_args(['add', 'reminder'])
    run_args(namespace)
    a = run_args(parse_args(['edit', 'reminder']))
    b = run_args(parse_args(['edit', '0']))
    c = run_args(parse_args(['edit', 'reminder.rem']))
    assert a == b
    assert b == c
    assert a == ['vim', str(REMIND_DIR / 'reminder.rem')]
예제 #4
0
def test_filename_collision(move_reminders, fname):
    """Adding with the same filename should raise an error."""
    clean_reminders()
    run_args(
        parse_args(['add', '-n', fname, "reminder1"],
                   parser_class=ErrorRaisingArgumentParser))
    with raises(ValueError) as error:
        run_args(
            parse_args(['add', '-n', fname, "reminder text"],
                       parser_class=ErrorRaisingArgumentParser))
    assert "already a reminder" in str(error)
예제 #5
0
def test_add_number_to_end(move_reminders):
    """Adding the same reminder text should result in files that are numbered."""
    clean_reminders()
    for _ in range(3):
        run_args(parse_args(['add', 'reminder']))

    for child in REMIND_DIR.iterdir():
        assert str(child.name) in [
            'reminder.rem', 'reminde000.rem', 'reminde001.rem'
        ]
        with child.open('r') as remind_file:
            assert remind_file.read() == 'reminder'
예제 #6
0
def test_list_reminder_names(capsys, move_reminders):
    """Test that reminders added are listed."""
    clean_reminders()
    run_args(parse_args(['add', 'reminder']))
    run_args(parse_args(['add', 'dothething']))
    run_args(parse_args(['add', 'another']))
    run_args(parse_args(['list']))
    out, err = capsys.readouterr()
    assert "2  reminder.rem" in out
    assert "1  dothething.rem" in out
    assert "0  another.rem" in out
    assert len(out.split('\n')) == 6
예제 #7
0
def test_list_not_long(capsys, move_reminders, reminder_text):
    """Make sure that list never prints too long a line."""
    assume(not reminder_text.startswith('-'))
    note(reminder_text)
    clean_reminders()
    len_space = 2
    len_index = 1
    len_filename = 10
    len_file_extension = 4
    len_reminder = 20

    len_line = len_index + len_space + len_filename + len_file_extension + len_space + len_reminder

    run_args(parse_args(['add', reminder_text]))

    run_args(parse_args(['ls']))
    out, err = capsys.readouterr()
    note(out)
    for line in out.split('\n'):
        assert len(line) <= len_line
예제 #8
0
def test_show_index_out_of_bounds(move_reminders):
    """Requesting by index when too large should raise an error."""
    clean_reminders()
    with raises(ValueError) as error:
        run_args(
            parse_args(['show', '0'], parser_class=ErrorRaisingArgumentParser))
    assert "List index out of range" in str(error)

    run_args(parse_args(['add', 'reminder']))
    run_args(parse_args(['show', '0'],
                        parser_class=ErrorRaisingArgumentParser))
    with raises(ValueError) as error2:
        run_args(
            parse_args(['show', '1'], parser_class=ErrorRaisingArgumentParser))
    assert "List index out of range" in str(error2)
예제 #9
0
def test_delete_by_force(capsys, move_reminders):
    """Test that force flag does not prompt."""
    clean_reminders()
    run_args(parse_args(['add', 'reminder']))
    run_args(parse_args(['delete', '-f', 'reminder']))
    run_args(parse_args(['list']))
    out, err = capsys.readouterr()
    assert "No reminders found" in out
예제 #10
0
def test_delete_reminder(capsys, move_reminders):
    """Test that delete actually deletes and prompts for deletion."""
    #TODO create test with lambda x: 'n'
    clean_reminders()
    run_args(parse_args(['add', 'reminder']))
    run_args(parse_args(['add', 'dothething']))
    run_args(parse_args(['add', 'another']))

    run_args(parse_args(['delete', 'reminder']))
    run_args(parse_args(['list']))
    out, err = capsys.readouterr()
    assert "reminder.rem" not in out
    assert "dothething.rem" in out
    assert "another.rem" in out

    run_args(parse_args(['delete', 'dothething.rem']))
    run_args(parse_args(['list']))
    out, err = capsys.readouterr()
    assert "dothething.rem" not in out
    assert "another.rem" in out

    run_args(parse_args(['delete', '0']))
    run_args(parse_args(['list']))
    out, err = capsys.readouterr()
    assert "No reminders found" in out
예제 #11
0
def test_show_reminder(capsys, move_reminders, reminder_text, filename):
    """Test that show works as expected."""
    clean_reminders()
    assume(not reminder_text.startswith('-'))

    add_parsed = parse_args(['add', '-n', 'A' + filename, 'A' + reminder_text])
    add_parsed2 = parse_args(
        ['add', '-n', 'Z' + filename, 'Z' + reminder_text])
    run_args(add_parsed)
    run_args(add_parsed2)

    # Test by index
    run_args(parse_args(['show', '0']))
    out, err = capsys.readouterr()
    assert out == 'A' + reminder_text + '\n'

    run_args(parse_args(['show', '1']))
    out, err = capsys.readouterr()
    assert out == 'Z' + reminder_text + '\n'

    # Test by filename
    run_args(parse_args(['show', add_parsed.fpath.name]))
    out, err = capsys.readouterr()
    assert out == 'A' + reminder_text + '\n'

    run_args(parse_args(['show', add_parsed2.fpath.name]))
    out, err = capsys.readouterr()
    assert out == 'Z' + reminder_text + '\n'

    # Test by filename minus extension
    name1, ext1 = get_parts(add_parsed.fpath.name)
    run_args(parse_args(['show', name1]))
    out, err = capsys.readouterr()
    assert out == 'A' + reminder_text + '\n'

    name2, ext2 = get_parts(add_parsed2.fpath.name)
    run_args(parse_args(['show', name2]))
    out, err = capsys.readouterr()
    assert out == 'Z' + reminder_text + '\n'
예제 #12
0
def test_print_help_when_no_arguments(capsys):
    """Test that when no arguments given to parse_args, help is printed."""
    run_args(parse_args([]))
    out, err = capsys.readouterr()
    assert "usage: " in out
예제 #13
0
def test_list_when_no_reminders(capsys, move_reminders):
    """Test that when no reminders exist, we handle that."""
    clean_reminders()
    run_args(parse_args(['list']))
    out, err = capsys.readouterr()
    assert "No reminders found" in out