Fix warning in tests (unclosed file)

This commit is contained in:
Klaas van Schelven
2025-01-31 13:17:20 +01:00
parent 102070bf24
commit 43a6049180
2 changed files with 13 additions and 3 deletions

View File

@@ -49,6 +49,11 @@ def _digest_params(event_data, project, request, now=None):
}
def _readlines(filename):
with open(filename) as f:
return f.readlines()
class IngestViewTestCase(TransactionTestCase):
# this TestCase started out as focussed on alert-sending, but has grown beyond that. Sometimes simply by extending
# existing tests. This is not a problem in itself, but may be slightly confusing if you don't realize that.
@@ -288,7 +293,7 @@ class IngestViewTestCase(TransactionTestCase):
SAMPLES_DIR = os.getenv("SAMPLES_DIR", "../event-samples")
event_samples = glob(SAMPLES_DIR + "/*/*.json")
known_broken = [SAMPLES_DIR + "/" + s.strip() for s in open(SAMPLES_DIR + "/KNOWN-BROKEN").readlines()]
known_broken = [SAMPLES_DIR + "/" + s.strip() for s in _readlines(SAMPLES_DIR + "/KNOWN-BROKEN")]
if len(event_samples) == 0:
raise Exception(f"No event samples found in {SAMPLES_DIR}; I insist on having some to test with.")
@@ -342,7 +347,7 @@ class IngestViewTestCase(TransactionTestCase):
SAMPLES_DIR = os.getenv("SAMPLES_DIR", "../event-samples")
event_samples = glob(SAMPLES_DIR + "/sentry/mobile1-xen.json") # this one has 'exception.values[0].type'
known_broken = [SAMPLES_DIR + "/" + s.strip() for s in open(SAMPLES_DIR + "/KNOWN-BROKEN").readlines()]
known_broken = [SAMPLES_DIR + "/" + s.strip() for s in _readlines(SAMPLES_DIR + "/KNOWN-BROKEN")]
if len(event_samples) == 0:
raise Exception(f"No event samples found in {SAMPLES_DIR}; I insist on having some to test with.")

View File

@@ -35,6 +35,11 @@ def fresh(obj):
return type(obj).objects.get(pk=obj.pk)
def _readlines(filename):
with open(filename) as f:
return f.readlines()
class RegressionUtilTestCase(RegularTestCase):
# This tests the concept of "what is a regression?", it _does not_ test for regressions in our code :-)
# this particular testcase tests straight on the utility `is_regression` (i.e. not all issue-handling code)
@@ -456,7 +461,7 @@ class IntegrationTest(TransactionTestCase):
event_samples = glob(SAMPLES_DIR + "/*/*.json")
event_samples_private = glob("../event-samples-private/*.json")
known_broken = [SAMPLES_DIR + "/" + s.strip() for s in open(SAMPLES_DIR + "/KNOWN-BROKEN").readlines()]
known_broken = [SAMPLES_DIR + "/" + s.strip() for s in _readlines(SAMPLES_DIR + "/KNOWN-BROKEN")]
if len(event_samples) == 0:
raise Exception(f"No event samples found in {SAMPLES_DIR}; I insist on having some to test with.")