コード例 #1
0
ファイル: test_microfs.py プロジェクト: damianburrin/microfs
def test_main_get():
    """
    If the get command is correctly issued, check the appropriate function is
    called.
    """
    with mock.patch('microfs.get', return_value=True) as mock_get:
            microfs.main(argv=['get', 'foo'])
            mock_get.assert_called_once_with('foo')
コード例 #2
0
ファイル: test_microfs.py プロジェクト: damianburrin/microfs
def test_main_ls():
    """
    If the ls command is issued, check the appropriate function is called.
    """
    with mock.patch('microfs.ls', return_value=['foo', 'bar']) as mock_ls:
        with mock.patch.object(builtins, 'print') as mock_print:
            microfs.main(argv=['ls'])
            mock_ls.assert_called_once_with()
            mock_print.assert_called_once_with('foo bar')
コード例 #3
0
ファイル: test_microfs.py プロジェクト: damianburrin/microfs
def test_main_handle_exception():
    """
    If an exception is raised, then it gets printed.
    """
    ex = ValueError('Error')
    with mock.patch('microfs.get', side_effect=ex):
        with mock.patch.object(builtins, 'print') as mock_print:
            microfs.main(argv=['get', 'foo'])
            mock_print.assert_called_once_with(ex)
コード例 #4
0
ファイル: test_microfs.py プロジェクト: damianburrin/microfs
def test_main_ls_no_files():
    """
    If the ls command is issued and no files exist, nothing is printed.
    """
    with mock.patch('microfs.ls', return_value=[]) as mock_ls:
        with mock.patch.object(builtins, 'print') as mock_print:
            microfs.main(argv=['ls'])
            mock_ls.assert_called_once_with()
            assert mock_print.call_count == 0
コード例 #5
0
ファイル: test_microfs.py プロジェクト: damianburrin/microfs
def test_main_no_args():
    """
    If no args are passed, simply display help.
    """
    with mock.patch('sys.argv', ['ufs', ]):
        mock_parser = mock.MagicMock()
        with mock.patch('microfs.argparse.ArgumentParser',
                        return_value=mock_parser):
            microfs.main()
        mock_parser.print_help.assert_called_once_with()
コード例 #6
0
ファイル: test_microfs.py プロジェクト: skylin008/microfs
def test_main_put_no_filename():
    """
    If put is not called with an associated filename, then print an error
    message.
    """
    with mock.patch("microfs.put", return_value=True) as mock_put:
        with mock.patch.object(builtins, "print") as mock_print:
            microfs.main(argv=["put"])
            assert mock_print.call_count == 1
            assert mock_put.call_count == 0
コード例 #7
0
ファイル: test_microfs.py プロジェクト: sleijon1/microfs
def test_main_get_no_filename():
    """
    If get is not called with an associated filename, then print an error
    message.
    """
    with mock.patch('microfs.get', return_value=True) as mock_get:
        with mock.patch.object(builtins, 'print') as mock_print:
            microfs.main(argv=['get'])
            assert mock_print.call_count == 1
            assert mock_get.call_count == 0
コード例 #8
0
ファイル: test_microfs.py プロジェクト: damianburrin/microfs
def test_main_get_no_filename():
    """
    If get is not called with an associated filename, then print an error
    message.
    """
    with mock.patch('microfs.get', return_value=True) as mock_get:
        with mock.patch.object(builtins, 'print') as mock_print:
            microfs.main(argv=['get'])
            assert mock_print.call_count == 1
            assert mock_get.call_count == 0
コード例 #9
0
ファイル: test_microfs.py プロジェクト: sleijon1/microfs
def test_main_get():
    """
    If the get command is correctly issued, check the appropriate function is
    called.
    """
    mock_serial = mock.MagicMock()
    mock_class = mock.MagicMock()
    mock_class.__enter__.return_value = mock_serial
    with mock.patch('microfs.get', return_value=True) as mock_get, \
            mock.patch('microfs.get_serial', return_value=mock_class):
        microfs.main(argv=['get', 'foo'])
        mock_get.assert_called_once_with('foo', None)
コード例 #10
0
ファイル: test_microfs.py プロジェクト: skylin008/microfs
def test_main_put():
    """
    If the put command is correctly issued, check the appropriate function is
    called.
    """
    mock_serial = mock.MagicMock()
    mock_class = mock.MagicMock()
    mock_class.__enter__.return_value = mock_serial
    with mock.patch("microfs.put", return_value=True) as mock_put, mock.patch(
            "microfs.get_serial", return_value=mock_class):
        microfs.main(argv=["put", "foo"])
        mock_put.assert_called_once_with("foo", None)
コード例 #11
0
ファイル: test_microfs.py プロジェクト: sleijon1/microfs
def test_main_handle_exception():
    """
    If an exception is raised, then it gets printed.
    """
    ex = ValueError('Error')
    mock_serial = mock.MagicMock()
    mock_class = mock.MagicMock()
    mock_class.__enter__.return_value = mock_serial
    with mock.patch('microfs.get', side_effect=ex), \
            mock.patch('microfs.get_serial', return_value=mock_class), \
            mock.patch.object(builtins, 'print') as mock_print:
        microfs.main(argv=['get', 'foo'])
        mock_print.assert_called_once_with(ex)
コード例 #12
0
def test_main_get_no_filename():
    """
    If get is not called with an associated filename, then print an error
    message.
    """
    with mock.patch("microfs.get", return_value=True) as mock_get:
        with mock.patch.object(builtins, "print") as mock_print, pytest.raises(
                SystemExit) as pytest_exc:
            microfs.main(argv=["get"])
    assert mock_print.call_count == 1
    assert mock_get.call_count == 0
    assert pytest_exc.type == SystemExit
    assert pytest_exc.value.code == 2
コード例 #13
0
ファイル: test_microfs.py プロジェクト: sleijon1/microfs
def test_main_ls_no_files():
    """
    If the ls command is issued and no files exist, nothing is printed.
    """
    mock_serial = mock.MagicMock()
    mock_class = mock.MagicMock()
    mock_class.__enter__.return_value = mock_serial
    with mock.patch('microfs.ls', return_value=[]) as mock_ls, \
            mock.patch('microfs.get_serial', return_value=mock_class), \
            mock.patch.object(builtins, 'print') as mock_print:
        microfs.main(argv=['ls'])
        mock_ls.assert_called_once_with()
        assert mock_print.call_count == 0
コード例 #14
0
ファイル: test_microfs.py プロジェクト: sleijon1/microfs
def test_main_ls():
    """
    If the ls command is issued, check the appropriate function is called.
    """
    mock_serial = mock.MagicMock()
    mock_class = mock.MagicMock()
    mock_class.__enter__.return_value = mock_serial
    with mock.patch('microfs.ls', return_value=['foo', 'bar']) as mock_ls, \
            mock.patch('microfs.get_serial', return_value=mock_class), \
            mock.patch.object(builtins, 'print') as mock_print:
        microfs.main(argv=['ls'])
        mock_ls.assert_called_once_with()
        mock_print.assert_called_once_with('foo bar')
コード例 #15
0
ファイル: test_microfs.py プロジェクト: skylin008/microfs
def test_main_handle_exception():
    """
    If an exception is raised, then it gets printed.
    """
    ex = ValueError("Error")
    mock_serial = mock.MagicMock()
    mock_class = mock.MagicMock()
    mock_class.__enter__.return_value = mock_serial
    with mock.patch("microfs.get", side_effect=ex), mock.patch(
            "microfs.get_serial",
            return_value=mock_class), mock.patch.object(builtins,
                                                        "print") as mock_print:
        microfs.main(argv=["get", "foo"])
        mock_print.assert_called_once_with(ex)
コード例 #16
0
ファイル: test_microfs.py プロジェクト: skylin008/microfs
def test_main_ls():
    """
    If the ls command is issued, check the appropriate function is called.
    """
    mock_serial = mock.MagicMock()
    mock_class = mock.MagicMock()
    mock_class.__enter__.return_value = mock_serial
    with mock.patch("microfs.ls",
                    return_value=["foo", "bar"]) as mock_ls, mock.patch(
                        "microfs.get_serial",
                        return_value=mock_class), mock.patch.object(
                            builtins, "print") as mock_print:
        microfs.main(argv=["ls"])
        mock_ls.assert_called_once_with()
        mock_print.assert_called_once_with("foo bar")
コード例 #17
0
def fs():
    import microfs
    microfs.main(sys.argv[2:])