From 3d38611e4f684da4819efa763d99a2df6eb83b15 Mon Sep 17 00:00:00 2001 From: Philip Sargent Date: Fri, 24 Feb 2023 20:21:06 +0000 Subject: [PATCH] new test for logbook --- core/TESTS/test_imports.py | 19 +++++++++++++++++++ parsers/logbooks.py | 8 +++++--- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/core/TESTS/test_imports.py b/core/TESTS/test_imports.py index 5474c63..d0b77c5 100644 --- a/core/TESTS/test_imports.py +++ b/core/TESTS/test_imports.py @@ -143,6 +143,25 @@ class SimpleTest(SimpleTestCase): from troggle.core.views.statistics import dataissues, pathsreport, stats from troggle.core.views.survex import survexcavesingle, survexcaveslist, svx +class ImportTest(TestCase): + @classmethod + def setUpTestData(cls): + import troggle.settings as settings + from troggle.parsers.logbooks import LOGBOOKS_DIR, DEFAULT_LOGBOOK_FILE + + LOGBOOKS_PATH = settings.EXPOWEB / LOGBOOKS_DIR + test_year = "1986" + self.test_logbook = LOGBOOKS_PATH / test_year / DEFAULT_LOGBOOK_FILE + + def setUp(self): + pass + + def tearDown(self): + pass + + def test_logbook_exists(self): + self.assertTrue(self.test_logbook.is_file()) + class SubprocessTest(TestCase): @classmethod diff --git a/parsers/logbooks.py b/parsers/logbooks.py index 47dd9ba..83a2660 100644 --- a/parsers/logbooks.py +++ b/parsers/logbooks.py @@ -56,6 +56,7 @@ DEFAULT_LOGBOOK_PARSER = "parser_html" LOGBOOK_PARSER_SETTINGS = { "1982": ("logbook.html", "parser_html"), } +LOGBOOKS_DIR = "years" # subfolder of settings.EXPOWEB ENTRIES = { "2022": 90, @@ -97,6 +98,7 @@ ENTRIES = { "1983": 52, "1982": 42, } +# What about 1970s ! Yes, 80 and 81 are missing, but the older ones need re-parsing !!! logentries = [] # the entire logbook for one year is a single object: a list of entries noncaveplaces = ["travel", "Journey", "Loser Plateau", "UNKNOWN", "plateau", "base camp", "basecamp", "top camp", "topcamp"] @@ -294,7 +296,7 @@ def parser_html(year, expedition, txt, seq=""): # print(f" - headpara:\n'{headpara}'") if len(headpara) > 0: - frontpath = Path(settings.EXPOWEB, "years", year, "frontmatter.html") + frontpath = Path(settings.EXPOWEB, LOGBOOKS_DIR, year, "frontmatter.html") with open(frontpath, "w") as front: front.write(headpara + "\n") @@ -304,7 +306,7 @@ def parser_html(year, expedition, txt, seq=""): # print(f" - endpara:\n'{endpara}'") if len(endpara) > 0: - endpath = Path(settings.EXPOWEB, "years", year, "endmatter.html") + endpath = Path(settings.EXPOWEB, LOGBOOKS_DIR, year, "endmatter.html") with open(endpath, "w") as end: end.write(endpara + "\n") @@ -511,7 +513,7 @@ def parse_logbook_for_expedition(expedition, blog=False): logentries = [] logbook_parseable = False - expologbase = Path(settings.EXPOWEB, "years") + expologbase = Path(settings.EXPOWEB, LOGBOOKS_DIR) year = expedition.year expect = ENTRIES[year]