diff --git a/notebooks/test_notebook.ipynb b/notebooks/test_notebook.ipynb new file mode 100644 index 0000000..68263a8 --- /dev/null +++ b/notebooks/test_notebook.ipynb @@ -0,0 +1,54 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'Hello world!'" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "import sys\n", + "import os\n", + "\n", + "# Gets the absolute path to the src folder\n", + "sys.path.append(os.path.abspath(\"../src\"))\n", + "\n", + "# Now we can import the fucntion from the module\n", + "from my_package.test_module import hello\n", + "\n", + "hello()\n" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "venv", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.12.5" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/src/my_package/__init__.py b/src/my_package/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/my_package/test_module.py b/src/my_package/test_module.py new file mode 100644 index 0000000..00f0438 --- /dev/null +++ b/src/my_package/test_module.py @@ -0,0 +1,2 @@ +def hello(): + return ("Hello World!") \ No newline at end of file diff --git a/tests/unit/test_test.py b/tests/unit/test_test.py new file mode 100644 index 0000000..509ca31 --- /dev/null +++ b/tests/unit/test_test.py @@ -0,0 +1,21 @@ +import unittest +import sys, os + +# This will make the absolute path, from the working directory, so it will not work every time, if we hav 'cd' into another folder +# sys.path.append(os.path.abspath("src")) + +# This will make the absolute path from the root of the project, and will therefor work every time +sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "../../src"))) + +# ^This problem will only occure when trying to run the test using the terminal + +from my_package import test_module + +class TestTest(unittest.TestCase): + def test_hello(self): + expected_output = "Hello World!" + self.assertEqual(test_module.hello(), expected_output) + + +if __name__ == '__main__': + unittest.main() \ No newline at end of file