Example #1
0
def test_main(monkeypatch):
    directory_entries = pretend.stub()

    @pretend.call_recorder
    def format_test(directory_entries, file):
        pass

    @pretend.call_recorder
    def getdents(path, buff_size=32768):
        return directory_entries

    monkeypatch.setitem(FORMATTERS, 'test', format_test)
    monkeypatch.setattr(cli, 'getdents', getdents)

    assert main(['x', '-o', 'test', '-b', '1024'], 'test') == 0
    assert getdents.calls == [pretend.call('x', buff_size=1024)]
    assert format_test.calls == [pretend.call(directory_entries, stdout)]
Example #2
0
def test_main_os_error(monkeypatch):
    monkeypatch.setattr(cli, 'getdents', pretend.raiser(OSError))

    assert main(['x']) == 7
Example #3
0
def test_main_permission_error(monkeypatch):
    monkeypatch.setattr(cli, 'getdents', pretend.raiser(PermissionError))

    assert main(['x']) == 6
Example #4
0
def test_main_not_a_directory_error(monkeypatch):
    monkeypatch.setattr(cli, 'getdents', pretend.raiser(NotADirectoryError))

    assert main(['x']) == 5
Example #5
0
def test_main_file_not_found_error(monkeypatch):
    monkeypatch.setattr(cli, 'getdents', pretend.raiser(FileNotFoundError))

    assert main(['x']) == 4
Example #6
0
def test_main_memory_error(monkeypatch):
    monkeypatch.setattr(cli, 'getdents', pretend.raiser(MemoryError))

    assert main(['x']) == 3