Ejemplo n.º 1
0
def test_get_distro_name_empty():
    """Calling get_distro_name() with an empty file should return the 'unknown'."""
    with mock.patch('builtins.open', mock.mock_open(),
                    create=True) as mocked_open:
        os = cli.get_distro_name()
        assert os == 'unknown'
        assert mock.call(cli.OS_RELEASE_FILE,
                         mode='r') in mocked_open.mock_calls
Ejemplo n.º 2
0
def test_get_distro_name():
    """Calling get_distro_name() should return the OS name."""
    with mock.patch('{mod}.open'.format(mod=BUILTINS),
                    mock.mock_open(read_data=OS_RELEASE),
                    create=True) as mocked_open:
        os = cli.get_distro_name()
        assert os == OS_NAME
        assert mock.call(cli.OS_RELEASE_FILE,
                         mode='r') in mocked_open.mock_calls
Ejemplo n.º 3
0
def test_get_distro_name_fail():
    """Calling get_distro_name() with an unreadable file, should return 'unknown'."""
    with mock.patch('builtins.open', mock.mock_open(),
                    create=True) as mocked_open:
        mocked_open.side_effect = IOError
        os = cli.get_distro_name()
        assert os == 'unknown'
        assert mock.call(cli.OS_RELEASE_FILE,
                         mode='r') in mocked_open.mock_calls