initial commit
This commit is contained in:
24
template/tests/{{ package_name }}/test_main.py.jinja
Normal file
24
template/tests/{{ package_name }}/test_main.py.jinja
Normal file
@@ -0,0 +1,24 @@
|
||||
import io
|
||||
import unittest
|
||||
import unittest.mock
|
||||
|
||||
import numpy as np
|
||||
|
||||
from {{ package_name }} import main
|
||||
|
||||
|
||||
class TestMain(unittest.TestCase):
|
||||
def test_get_np_array(self) -> None:
|
||||
np.testing.assert_array_equal(main.get_np_array(), np.array([0]))
|
||||
|
||||
@unittest.mock.patch("sys.stdout", new_callable=io.StringIO)
|
||||
def test_main(self, mock_stdout: unittest.mock.Mock) -> None:
|
||||
"""Test main method by executing it and comparing terminal output to expected values."""
|
||||
main.main("world")
|
||||
# Go to beginning of output
|
||||
mock_stdout.seek(0)
|
||||
self.assertEqual(mock_stdout.readline(), "Hello world!\n")
|
||||
self.assertEqual(
|
||||
mock_stdout.readline(),
|
||||
"Here's a test that poetry dependencies are installed: [0]\n",
|
||||
)
|
||||
Reference in New Issue
Block a user