From fdcc1369e27174373b305a6a9854f4b40e4d34d9 Mon Sep 17 00:00:00 2001 From: frankknoll Date: Wed, 14 Dec 2022 11:35:25 +0100 Subject: [PATCH] refactoring --- src/intensivstationen/Intensivstationen.ipynb | 80 +------------------ .../KreisOptionsSetterTest.py | 73 +++++++++++++++++ src/intensivstationen/__init__.py | 0 3 files changed, 74 insertions(+), 79 deletions(-) create mode 100644 src/intensivstationen/KreisOptionsSetterTest.py create mode 100644 src/intensivstationen/__init__.py diff --git a/src/intensivstationen/Intensivstationen.ipynb b/src/intensivstationen/Intensivstationen.ipynb index 9ff435b0a6e..77969777c75 100644 --- a/src/intensivstationen/Intensivstationen.ipynb +++ b/src/intensivstationen/Intensivstationen.ipynb @@ -8,6 +8,7 @@ "outputs": [], "source": [ "import os\n", + "import sys\n", "\n", "module_path = os.path.abspath(os.path.join('..'))\n", "if module_path not in sys.path:\n", @@ -235,85 +236,6 @@ " return pd.DataFrame(index = index, columns = columns, data = data).astype(dtypes)\n" ] }, - { - "cell_type": "code", - "execution_count": null, - "id": "e4f8fa80", - "metadata": {}, - "outputs": [], - "source": [ - "class KreisOptionsSetterTest(unittest.TestCase):\n", - "\n", - " def test_setKreisOptions(self):\n", - " # Given\n", - " kreisOptionsSetter = KreisOptionsSetter()\n", - "\n", - " # When\n", - " htmlActual = kreisOptionsSetter.setKreisOptions(\n", - " html='''\n", - " \n", - " \n", - "

Test

\n", - " \n", - " \n", - " \n", - " ''',\n", - " options=[\n", - " '',\n", - " '',\n", - " ''])\n", - "\n", - " # Then\n", - " assertEqualHTML(\n", - " htmlActual,\n", - " '''\n", - " \n", - " \n", - "

Test

\n", - " \n", - " \n", - " \n", - " ''')\n", - "\n", - "# adapted from https://stackoverflow.com/questions/8006909/pretty-print-assertequal-for-html-strings\n", - "def assertEqualHTML(string1, string2, file1='', file2=''):\n", - " u'''\n", - " Compare two unicode strings containing HTML.\n", - " A human friendly diff goes to logging.error() if they\n", - " are not equal, and an exception gets raised.\n", - " '''\n", - " from bs4 import BeautifulSoup as bs\n", - " import difflib\n", - "\n", - " def short(mystr):\n", - " max = 20\n", - " if len(mystr) > max:\n", - " return mystr[:max]\n", - " return mystr\n", - " p = []\n", - " for mystr, file in [(string1, file1), (string2, file2)]:\n", - " if not isinstance(mystr, str):\n", - " raise Exception(u'string ist not unicode: %r %s' %\n", - " (short(mystr), file))\n", - " soup = bs(mystr)\n", - " pretty = soup.prettify()\n", - " p.append(pretty)\n", - " if p[0] != p[1]:\n", - " for line in difflib.unified_diff(p[0].splitlines(), p[1].splitlines(), fromfile=file1, tofile=file2):\n", - " display(line)\n", - " display(p[0], ' != ', p[1])\n", - " raise Exception('Not equal %s %s' % (file1, file2))\n" - ] - }, { "cell_type": "code", "execution_count": null, diff --git a/src/intensivstationen/KreisOptionsSetterTest.py b/src/intensivstationen/KreisOptionsSetterTest.py new file mode 100644 index 00000000000..bd319843741 --- /dev/null +++ b/src/intensivstationen/KreisOptionsSetterTest.py @@ -0,0 +1,73 @@ +import unittest +from intensivstationen.KreisOptionsSetter import KreisOptionsSetter + +class KreisOptionsSetterTest(unittest.TestCase): + + def test_setKreisOptions(self): + # Given + kreisOptionsSetter = KreisOptionsSetter() + + # When + htmlActual = kreisOptionsSetter.setKreisOptions( + html=''' + + +

Test

+ + + + ''', + options=[ + '', + '', + '']) + + # Then + assertEqualHTML( + htmlActual, + ''' + + +

Test

+ + + + ''') + +# adapted from https://stackoverflow.com/questions/8006909/pretty-print-assertequal-for-html-strings +def assertEqualHTML(string1, string2, file1='', file2=''): + u''' + Compare two unicode strings containing HTML. + A human friendly diff goes to logging.error() if they + are not equal, and an exception gets raised. + ''' + from bs4 import BeautifulSoup as bs + import difflib + + def short(mystr): + max = 20 + if len(mystr) > max: + return mystr[:max] + return mystr + p = [] + for mystr, file in [(string1, file1), (string2, file2)]: + if not isinstance(mystr, str): + raise Exception(u'string ist not unicode: %r %s' % + (short(mystr), file)) + soup = bs(mystr) + pretty = soup.prettify() + p.append(pretty) + if p[0] != p[1]: + for line in difflib.unified_diff(p[0].splitlines(), p[1].splitlines(), fromfile=file1, tofile=file2): + display(line) + display(p[0], ' != ', p[1]) + raise Exception('Not equal %s %s' % (file1, file2)) diff --git a/src/intensivstationen/__init__.py b/src/intensivstationen/__init__.py new file mode 100644 index 00000000000..e69de29bb2d