Update test output

This commit is contained in:
Joe Farebrother
2025-09-05 22:43:21 +01:00
parent bd3fa7fb21
commit 0b293eaba5
2 changed files with 22 additions and 11 deletions

View File

@@ -4,7 +4,7 @@
| resources_test.py:112:11:112:28 | ControlFlowNode for opener_func2() | File may not be closed if $@ raises an exception. | resources_test.py:113:5:113:22 | ControlFlowNode for Attribute() | this operation |
| resources_test.py:123:11:123:24 | ControlFlowNode for opener_func2() | File is opened but is not closed. | file://:0:0:0:0 | (none) | this operation |
| resources_test.py:129:15:129:24 | ControlFlowNode for open() | File may not be closed if $@ raises an exception. | resources_test.py:130:9:130:26 | ControlFlowNode for Attribute() | this operation |
| resources_test.py:154:15:154:24 | ControlFlowNode for open() | File may not be closed if $@ raises an exception. | resources_test.py:159:9:159:18 | ControlFlowNode for Attribute() | this operation |
| resources_test.py:248:11:248:25 | ControlFlowNode for open() | File is opened but is not closed. | file://:0:0:0:0 | (none) | this operation |
| resources_test.py:269:10:269:27 | ControlFlowNode for Attribute() | File may not be closed if $@ raises an exception. | resources_test.py:271:5:271:19 | ControlFlowNode for Attribute() | this operation |
| resources_test.py:285:11:285:20 | ControlFlowNode for open() | File may not be closed if $@ raises an exception. | resources_test.py:287:5:287:31 | ControlFlowNode for Attribute() | this operation |
| resources_test.py:305:10:305:19 | ControlFlowNode for open() | File may not be closed if $@ raises an exception. | resources_test.py:308:5:308:24 | ControlFlowNode for Attribute() | this operation |

View File

@@ -151,11 +151,11 @@ def not_closed17():
#With statement will close the fp
def closed18(path):
try:
f18 = open(path)
f18 = open(path) # $SPURIOUS: Alert # Dataflow appears to not detect this with statement as guarding the exceptions produced by the `read()` call.
except IOError as ex:
print(ex)
raise ex
with f18:
with f18:
f18.read()
class Closed19(object):
@@ -286,7 +286,7 @@ def closed29(path):
f28.close()
f28.write("already closed")
# False positive:
# False positive in a previous implementation:
class NotWrapper:
def __init__(self, fp):
@@ -297,12 +297,13 @@ class NotWrapper:
pass
def closed30(path):
# Combination of approximations resulting in this FP:
# Combination of approximations resulted in this FP:
# - NotWrapper is treated as a wrapper class as a file handle is passed to it
# - thing.do_something() is treated as a call that can raise an exception while a file is open
# - this call is treated as occurring after the open but not as being guarded by the with statement, as it is in the same basic block
# - - this behaviour has been changed fixing the FP
with open(path) as fp: # $SPURIOUS:Alert # not closed on exception
with open(path) as fp: # No longer spurious alert here.
thing = NotWrapper(fp)
thing.do_something()
@@ -314,10 +315,20 @@ def closed31(path):
data2 = fp.readline()
class FlowReader():
class Wrapper():
def __init__(self, f):
self.f = f
def read(self):
return self.f.read()
def __enter__(self):
pass
def test_cannot_convert(tdata):
with open(tdata, "rb") as f:
flow_reader = FlowReader(f)
list(flow_reader.stream())
def __exit__(self):
self.f.close()
def closed32(path):
with open(path, "rb") as f: # No longer spurious alert here.
wrap = Wrapper(f)
# This resulted in an FP in a previous implementation,
# due to a check that an operation is lexically contained within a `with` block (with `expr.getParent*()`)
# not detecting this case.
return list(wrap.read())