-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test of module, notebook and unittest
- Loading branch information
toravest
committed
Mar 6, 2025
1 parent
0760588
commit 4f7dd7f
Showing
4 changed files
with
77 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 | ||
| } |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| def hello(): | ||
| return ("Hello World!") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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() |