Skip to content
Snippets Groups Projects
Commit 24dcfec0 authored by Nathan Hertz's avatar Nathan Hertz
Browse files

Changed test naming convention. Added custom fixture for initializing Null object.

parent 639ec67c
No related branches found
No related tags found
No related merge requests found
import pytest
import argparse
from null.null import Null
# from null.null import Null
from ..src.null.null import Null
parser = argparse.ArgumentParser()
def test_print_error(caplog):
@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(caplog):
null = Null(argparse.Namespace(), True)
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(caplog):
null = Null(argparse.Namespace(), True)
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(caplog):
null = Null(argparse.Namespace(), True)
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(caplog):
null = Null(argparse.Namespace(), True)
def test_take_nap(null, caplog):
null.take_nap()
assert 'Going to sleep...' in caplog.text
assert 'Waking up.' in caplog.text
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment