Skip to content
Snippets Groups Projects
test_null.py 1.02 KiB
import pytest
import argparse

# from null.null import Null
from ..src.null.null import Null

@pytest.fixture()
def null():
    null = Null(argparse.Namespace(), True)
    return null

def test_print_error(null, caplog):
    null.print_error()
    assert 'ERROR: This is an error.' in caplog.text

def test_print_greeting(null, caplog):
    null.print_greeting()
    assert 'Hello, world!' in caplog.text
    assert 'And goodbye, world...' in caplog.text

def test_exit_with_failure(null, caplog):
    with pytest.raises(SystemExit) as e:
        null.exit_with_failure()
        assert 'Error purposefully induced. Exiting with status code -1...' in caplog.text
        assert e.value.code == -1

def test_exit_randomly(null, caplog):
    with pytest.raises(SystemExit) as e:
        null.exit_randomly()
        assert 'Exiting with status code' in caplog.text
        assert -50 <= e.value.code <= 50

def test_take_nap(null, caplog):
    null.take_nap()
    assert 'Going to sleep...' in caplog.text
    assert 'Waking up.' in caplog.text