Esempio n. 1
0
def test_sort_and_print_entries_excludes_paths_between_of_20_to_100_with_reverse_filter_option():
    with patch(mock_print) as p:
        # tmp/a1/path1
        # tmp/a1 (1)/path1
        # tmp/a130/path1
        sort_and_print_entries(entries, Args(None, [(20, 100)], False, True, False))
        e = [call(entries[i]) for i in [2, 3, 4]]
        p.assert_has_calls(e)
Esempio n. 2
0
def test_sort_and_print_entries_keeps_only_paths_between_of_20_to_100_with_filter_option():
    with patch(mock_print) as p:
        # tmp/a23/path1
        # tmp/a57/path2
        # tmp/a64/path1
        # tmp/a64/path2
        sort_and_print_entries(entries, Args([(20, 100)], None, False, False, False))
        e = [call(entries[i]) for i in [1, 0, 5, 6]]
        p.assert_has_calls(e)
Esempio n. 3
0
def test_sort_and_print_entries_excludes_paths_23_or_130_with_exclude_option_list():
    with patch(mock_print) as p:
        # tmp/a1/path1
        # tmp/a1 (1)/path1
        # tmp/a57/path2
        # tmp/a64/path1
        # tmp/a64/path2
        sort_and_print_entries(entries, Args(None, None, [23, 130], True, False))
        e = [call(entries[i]) for i in [2, 3, 0, 5, 6]]
        p.assert_has_calls(e)
Esempio n. 4
0
def test_sort_and_print_entries_excludes_paths_between_of_20_to_100_with_reverse_filter_option(
):
    with patch(mock_print) as p:
        # tmp/a1/path1
        # tmp/a1 (1)/path1
        # tmp/a130/path1
        sort_and_print_entries(entries,
                               Args(None, [(20, 100)], False, True, False))
        e = [call(entries[i]) for i in [2, 3, 4]]
        p.assert_has_calls(e)
Esempio n. 5
0
def test_sort_and_print_entries_keeps_only_paths_between_of_20_to_100_with_filter_option(
):
    with patch(mock_print) as p:
        # tmp/a23/path1
        # tmp/a57/path2
        # tmp/a64/path1
        # tmp/a64/path2
        sort_and_print_entries(entries,
                               Args([(20, 100)], None, False, False, False))
        e = [call(entries[i]) for i in [1, 0, 5, 6]]
        p.assert_has_calls(e)
Esempio n. 6
0
def test_sort_and_print_entries_uses_default_algorithm_with_all_options_false():
    with patch(mock_print) as p:
        # tmp/a1 (1)/path1
        # tmp/a1/path1
        # tmp/a23/path1
        # tmp/a57/path2
        # tmp/a64/path1
        # tmp/a64/path2
        # tmp/a130/path1
        sort_and_print_entries(entries, Args(None, None, False, False, False))
        e = [call(entries[i]) for i in [3, 2, 1, 0, 5, 6, 4]]
        p.assert_has_calls(e)
Esempio n. 7
0
def test_sort_and_print_entries_reverses_order_with_reverse_option():
    with patch(mock_print) as p:
        # tmp/a130/path1
        # tmp/a64/path2
        # tmp/a64/path1
        # tmp/a57/path2
        # tmp/a23/path1
        # tmp/a1 (1)/path1
        # tmp/a1/path1
        sort_and_print_entries(entries, Args(None, None, False, True, True))
        e = [call(entries[i]) for i in reversed([2, 3, 1, 0, 5, 6, 4])]
        p.assert_has_calls(e)
Esempio n. 8
0
def test_sort_and_print_entries_uses_PATH_algorithm_with_path_option_true_to_properly_sort_OS_generated_path_names():
    with patch(mock_print) as p:
        # tmp/a1/path1
        # tmp/a1 (1)/path1
        # tmp/a23/path1
        # tmp/a57/path2
        # tmp/a64/path1
        # tmp/a64/path2
        # tmp/a130/path1
        sort_and_print_entries(entries, Args(None, None, False, True, False))
        e = [call(entries[i]) for i in [2, 3, 1, 0, 5, 6, 4]]
        p.assert_has_calls(e)
Esempio n. 9
0
def test_sort_and_print_entries_reverses_order_with_reverse_option():
    with patch(mock_print) as p:
        # tmp/a130/path1
        # tmp/a64/path2
        # tmp/a64/path1
        # tmp/a57/path2
        # tmp/a23/path1
        # tmp/a1 (1)/path1
        # tmp/a1/path1
        sort_and_print_entries(entries, Args(None, None, False, True, True))
        e = [call(entries[i]) for i in reversed([2, 3, 1, 0, 5, 6, 4])]
        p.assert_has_calls(e)
Esempio n. 10
0
def test_sort_and_print_entries_excludes_paths_23_or_130_with_exclude_option_list(
):
    with patch(mock_print) as p:
        # tmp/a1/path1
        # tmp/a1 (1)/path1
        # tmp/a57/path2
        # tmp/a64/path1
        # tmp/a64/path2
        sort_and_print_entries(entries, Args(None, None, [23, 130], True,
                                             False))
        e = [call(entries[i]) for i in [2, 3, 0, 5, 6]]
        p.assert_has_calls(e)
Esempio n. 11
0
def test_sort_and_print_entries_uses_default_algorithm_with_all_options_false(
):
    with patch(mock_print) as p:
        # tmp/a1 (1)/path1
        # tmp/a1/path1
        # tmp/a23/path1
        # tmp/a57/path2
        # tmp/a64/path1
        # tmp/a64/path2
        # tmp/a130/path1
        sort_and_print_entries(entries, Args(None, None, False, False, False))
        e = [call(entries[i]) for i in [3, 2, 1, 0, 5, 6, 4]]
        p.assert_has_calls(e)
Esempio n. 12
0
def test_sort_and_print_entries_uses_PATH_algorithm_with_path_option_true_to_properly_sort_OS_generated_path_names(
):
    with patch(mock_print) as p:
        # tmp/a1/path1
        # tmp/a1 (1)/path1
        # tmp/a23/path1
        # tmp/a57/path2
        # tmp/a64/path1
        # tmp/a64/path2
        # tmp/a130/path1
        sort_and_print_entries(entries, Args(None, None, False, True, False))
        e = [call(entries[i]) for i in [2, 3, 1, 0, 5, 6, 4]]
        p.assert_has_calls(e)
Esempio n. 13
0
def test_sort_and_print_entries(options, order, mocker):
    p = mocker.patch(mock_print)
    sort_and_print_entries(entries, Args(*options))
    e = [mocker.call(entries[i]) for i in order]
    p.assert_has_calls(e)
Esempio n. 14
0
def test_sort_and_print_entries(options, order, mocker):
    p = mocker.patch(mock_print)
    sort_and_print_entries(entries, Args(*options))
    e = [mocker.call(entries[i]) for i in order]
    p.assert_has_calls(e)
Esempio n. 15
0
def test_sort_and_print_entries(capsys):
    class Args:
        """A dummy class to simulate the argparse Namespace object"""
        def __init__(self, filter, reverse_filter, exclude, as_path, reverse):
            self.filter = filter
            self.reverse_filter = reverse_filter
            self.exclude = exclude
            self.reverse = reverse
            self.number_type = 'float'
            self.signed = True
            self.exp = True
            self.paths = as_path
            self.locale = 0

    entries = [
        'tmp/a57/path2', 'tmp/a23/path1', 'tmp/a1/path1', 'tmp/a1 (1)/path1',
        'tmp/a130/path1', 'tmp/a64/path1', 'tmp/a64/path2'
    ]

    # Just sort the paths
    sort_and_print_entries(entries, Args(None, None, False, False, False))
    out, __ = capsys.readouterr()
    assert out == """\
tmp/a1 (1)/path1
tmp/a1/path1
tmp/a23/path1
tmp/a57/path2
tmp/a64/path1
tmp/a64/path2
tmp/a130/path1
"""

    # You would use --paths to make them sort
    # as paths when the OS makes duplicates
    sort_and_print_entries(entries, Args(None, None, False, True, False))
    out, __ = capsys.readouterr()
    assert out == """\
tmp/a1/path1
tmp/a1 (1)/path1
tmp/a23/path1
tmp/a57/path2
tmp/a64/path1
tmp/a64/path2
tmp/a130/path1
"""

    # Sort the paths with numbers between 20-100
    sort_and_print_entries(entries, Args([(20, 100)], None, False, False,
                                         False))
    out, __ = capsys.readouterr()
    assert out == """\
tmp/a23/path1
tmp/a57/path2
tmp/a64/path1
tmp/a64/path2
"""

    # Sort the paths without numbers between 20-100
    sort_and_print_entries(entries, Args(None, [(20, 100)], False, True,
                                         False))
    out, __ = capsys.readouterr()
    assert out == """\
tmp/a1/path1
tmp/a1 (1)/path1
tmp/a130/path1
"""

    # Sort the paths, excluding 23 and 130
    sort_and_print_entries(entries, Args(None, None, [23, 130], True, False))
    out, __ = capsys.readouterr()
    assert out == """\
tmp/a1/path1
tmp/a1 (1)/path1
tmp/a57/path2
tmp/a64/path1
tmp/a64/path2
"""

    # Sort the paths, excluding 2
    sort_and_print_entries(entries, Args(None, None, [2], False, False))
    out, __ = capsys.readouterr()
    assert out == """\
tmp/a1 (1)/path1
tmp/a1/path1
tmp/a23/path1
tmp/a64/path1
tmp/a130/path1
"""

    # Sort in reverse order
    sort_and_print_entries(entries, Args(None, None, False, True, True))
    out, __ = capsys.readouterr()
    assert out == """\