-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshowcase4.py
More file actions
66 lines (54 loc) · 2.2 KB
/
showcase4.py
File metadata and controls
66 lines (54 loc) · 2.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
from humandeltadebug import DD
import argparse
import os
'''
This example contains a test to show the use of dd to find a reference to a non-existent file.
The test case will fail if the file does not exist.
'''
class MissingFile(DD):
def _test(self, c):
python_code = DD.config_to_string(c)
if python_code.strip() == "":
return self.PASS
try:
# Simulate reading from a file
if not os.path.exists(python_code.strip()):
raise FileNotFoundError(f"File {python_code.strip()} not found.")
return self.PASS
except FileNotFoundError as e:
return self.FAIL
except Exception as e:
return self.UNRESOLVED
def coerce(self, c):
return DD.config_to_string(c)
# Failing code (file not found)
failing_code = 'showcase4/test/path/to/existing/file1.txt'
# Passing code (correct file path)
passing_code = 'showcase4/test/path/to/existing/file.txt'
failing_config = DD.string_to_config(failing_code)
passing_config = DD.string_to_config(passing_code)
# Delta Debugging setup
dd = MissingFile()
# For testing verbose flag
parser = argparse.ArgumentParser()
parser.add_argument('--verbose', action='store_true', help='Enable verbose output')
args = parser.parse_args()
# Set verbosity for delta debugging
dd.verbose = 1 if args.verbose else 0
# Get minimal failing configuration
minimal_config = dd.dd(failing_config)
minimal_failing = DD.config_to_string(minimal_config[0])
print("**********")
print("* Test 1 *")
print("**********************************************")
print("Failing test case to be minimised: \n " + failing_code)
print("**********************************************")
print("Minimal failing test case: \n" + minimal_failing)
print("**********************************************")
print("Passing test case to be maximised with respect to: \n" + passing_code)
# Get maximal failing configuration
max_config = dd.ddmax(DD.string_to_config(minimal_failing), passing_config, 2)
maximal_failing = DD.config_to_string(max_config[1])
print("**********************************************")
print("Maximal failing test case: \n" + maximal_failing)
print("**********************************************")