From 2e55d28a1066e516eba96fefafde6fa81afa02a0 Mon Sep 17 00:00:00 2001 From: Veronica Berglyd Olsen <1619840+vkbo@users.noreply.github.com> Date: Thu, 15 Feb 2024 21:46:35 +0100 Subject: [PATCH] Improve the test file compare function --- tests/tools.py | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/tests/tools.py b/tests/tools.py index 6346432b..835a61f5 100644 --- a/tests/tools.py +++ b/tests/tools.py @@ -70,20 +70,19 @@ def cmpFiles( ignoreLines = [] try: - foOne = open(fileOne, mode="r", encoding="utf-8") + with open(fileOne, mode="r", encoding="utf-8") as fo: + txtOne = fo.read().strip().splitlines() except Exception as exc: print(str(exc)) return False try: - foTwo = open(fileTwo, mode="r", encoding="utf-8") + with open(fileTwo, mode="r", encoding="utf-8") as fo: + txtTwo = fo.read().strip().splitlines() except Exception as exc: print(str(exc)) return False - txtOne = foOne.readlines() - txtTwo = foTwo.readlines() - if len(txtOne) != len(txtTwo): print("Files are not the same length") return False @@ -108,9 +107,6 @@ def cmpFiles( print(" >> '%s'" % lnTwo) diffFound = True - foOne.close() - foTwo.close() - return not diffFound