refactoring

This commit is contained in:
frankknoll
2022-12-14 11:35:25 +01:00
parent 1163f95a15
commit fdcc1369e2
3 changed files with 74 additions and 79 deletions

View File

@@ -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",
" <html>\n",
" <body>\n",
" <p>Test<p/>\n",
" <select id=\"kreisSelect\" name=\"kreis\">\n",
" <option selected=\"\" value=\"de\">Alle Landkreise</option>\n",
" <option value=\"Ahrweiler\">Ahrweiler</option>\n",
" <option value=\"Wiesbaden, Landeshauptstadt\">Wiesbaden, Landeshauptstadt</option>\n",
" <option value=\"Aichach-Friedberg\">Aichach-Friedberg</option>\n",
" </select>\n",
" </body>\n",
" </html>\n",
" ''',\n",
" options=[\n",
" '<option selected=\"\" value=\"de\">Alle Landkreise</option>',\n",
" '<option value=\"Ahrweiler\">Ahrweiler</option>',\n",
" '<option value=\"Aichach-Friedberg\">Aichach-Friedberg</option>'])\n",
"\n",
" # Then\n",
" assertEqualHTML(\n",
" htmlActual,\n",
" '''\n",
" <html>\n",
" <body>\n",
" <p>Test<p/>\n",
" <select id=\"kreisSelect\" name=\"kreis\">\n",
" <option selected=\"\" value=\"de\">Alle Landkreise</option>\n",
" <option value=\"Ahrweiler\">Ahrweiler</option>\n",
" <option value=\"Aichach-Friedberg\">Aichach-Friedberg</option>\n",
" </select>\n",
" </body>\n",
" </html>\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,