testgenie-py 0.2.8__py3-none-any.whl → 0.3.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. testgen/.coverage +0 -0
  2. testgen/code_to_test/code_to_fuzz.py +315 -220
  3. testgen/controller/docker_controller.py +12 -11
  4. testgen/service/service.py +10 -3
  5. testgen/testgen.db +0 -0
  6. testgen/tests/{test_code_to_fuzz_lite.py → test_code_to_fuzz.py} +127 -115
  7. {testgenie_py-0.2.8.dist-info → testgenie_py-0.3.0.dist-info}/METADATA +1 -1
  8. {testgenie_py-0.2.8.dist-info → testgenie_py-0.3.0.dist-info}/RECORD +10 -41
  9. testgen/generated_boolean.py +0 -48
  10. testgen/generated_samplecodebin.py +0 -545
  11. testgen/tests/test_boolean.py +0 -81
  12. testgen/tests/test_generated_boolean.py +0 -83
  13. testgen/visualize/boolean_bin_and_coverage.png +0 -0
  14. testgen/visualize/boolean_bin_and_coverage_v1.png +0 -0
  15. testgen/visualize/boolean_bin_and_coverage_v2.png +0 -0
  16. testgen/visualize/boolean_bin_and_coverage_v3.png +0 -0
  17. testgen/visualize/boolean_bin_and_coverage_v4.png +0 -0
  18. testgen/visualize/boolean_bin_and_coverage_v5.png +0 -0
  19. testgen/visualize/boolean_bin_and_coverage_v6.png +0 -0
  20. testgen/visualize/boolean_bin_and_coverage_v7.png +0 -0
  21. testgen/visualize/boolean_bin_and_coverage_v8.png +0 -0
  22. testgen/visualize/boolean_bin_xor_coverage.png +0 -0
  23. testgen/visualize/boolean_bin_xor_coverage_v1.png +0 -0
  24. testgen/visualize/boolean_bin_xor_coverage_v2.png +0 -0
  25. testgen/visualize/boolean_bin_xor_coverage_v3.png +0 -0
  26. testgen/visualize/boolean_bin_xor_coverage_v4.png +0 -0
  27. testgen/visualize/boolean_bin_xor_coverage_v5.png +0 -0
  28. testgen/visualize/boolean_bin_xor_coverage_v6.png +0 -0
  29. testgen/visualize/boolean_bin_xor_coverage_v7.png +0 -0
  30. testgen/visualize/boolean_bin_xor_coverage_v8.png +0 -0
  31. testgen/visualize/boolean_status_flags_coverage.png +0 -0
  32. testgen/visualize/boolean_status_flags_coverage_v1.png +0 -0
  33. testgen/visualize/boolean_status_flags_coverage_v2.png +0 -0
  34. testgen/visualize/boolean_status_flags_coverage_v3.png +0 -0
  35. testgen/visualize/boolean_status_flags_coverage_v4.png +0 -0
  36. testgen/visualize/boolean_status_flags_coverage_v5.png +0 -0
  37. testgen/visualize/boolean_status_flags_coverage_v6.png +0 -0
  38. testgen/visualize/boolean_status_flags_coverage_v7.png +0 -0
  39. testgen/visualize/boolean_status_flags_coverage_v8.png +0 -0
  40. {testgenie_py-0.2.8.dist-info → testgenie_py-0.3.0.dist-info}/WHEEL +0 -0
  41. {testgenie_py-0.2.8.dist-info → testgenie_py-0.3.0.dist-info}/entry_points.txt +0 -0
testgen/.coverage CHANGED
Binary file
@@ -1,20 +1,13 @@
1
- from typing import List
2
-
3
-
4
- def bin_and(a: bool, b: bool) ->bool:
5
- """"
6
- >>> bin_and(True, True)
7
- True
8
- >>> bin_and(True, False)
9
- False
10
- >>> bin_and(False, True)
11
- False
12
- >>> bin_and(False, False)
13
- False
14
-
15
- Examples:
16
- >>> bin_and(True, False)
17
- False"""
1
+ def random_fuzz_code(x: int, y: int) -> int:
2
+ result = x
3
+ if x < y:
4
+ result += y
5
+ else:
6
+ result -= y
7
+ return result
8
+
9
+
10
+ def bin_and(a: bool, b: bool) -> bool:
18
11
  if a == True:
19
12
  if b == True:
20
13
  return True
@@ -24,211 +17,313 @@ def bin_and(a: bool, b: bool) ->bool:
24
17
  return False
25
18
 
26
19
 
27
- def bin_or(a: bool, b: bool) ->bool:
28
- """"
29
- >>> bin_or(True, True)
30
- True
31
- >>> bin_or(True, False)
32
- True
33
- >>> bin_or(False, True)
34
- True
35
- >>> bin_or(False, False)
36
- False
37
-
38
- Examples:
39
- >>> bin_or(False, True)
40
- True"""
41
- return a | b
42
-
43
-
44
- def bin_xor(a: bool, b: bool) ->bool:
45
- """>>> bin_xor(True, True)
46
- False
47
- >>> bin_xor(True, False)
48
- True
49
- >>> bin_xor(False, True)
50
- True
51
- >>> bin_xor(False, False)
52
- False
53
-
54
- Examples:
55
- >>> bin_xor(True, True)
56
- False"""
57
- return a ^ b
58
-
59
-
60
- def bin_nand(a: bool, b: bool) ->bool:
61
- """>>> bin_nand(True, True)
62
- False
63
- >>> bin_nand(True, False)
64
- True
65
- >>> bin_nand(False, True)
66
- True
67
- >>> bin_nand(False, False)
68
- True
69
-
70
- Examples:
71
- >>> bin_nand(True, False)
72
- True"""
73
- return not (a and b)
74
-
75
-
76
- def bin_nor(a: bool, b: bool) ->bool:
77
- """>>> bin_nor(True, True)
78
- False
79
- >>> bin_nor(True, False)
80
- False
81
- >>> bin_nor(False, True)
82
- False
83
- >>> bin_nor(False, False)
84
- True
85
-
86
- Examples:
87
- >>> bin_nor(False, True)
88
- False"""
89
- return not a | b
90
-
91
-
92
- def mux(c1: bool, c2: bool, x0: bool, x1: bool, x2: bool, x3: bool) ->bool:
93
- """"
94
- >>> mux(1, 1, True, False, False, False)
95
- True
96
- >>> mux(1, 0, False, True, False, False)
97
- True
98
- >>> mux(0, 1, False, False, True, False)
99
- True
100
- >>> mux(0, 0, False, False, False, True)
101
- True
102
- >>> mux(0, 0, False, False, False, False)
103
- False
104
-
105
- Examples:
106
- >>> mux(False, False, False, False, False, True)
107
- True"""
108
- return (c1 and c2 and x0) | (c1 and not c2 and x1) | (not c1 and c2 and x2
109
- ) | (not c1 and not c2 and x3)
110
-
111
-
112
- def bin_and_bad(a: bool, b: bool) ->bool:
113
- """"
114
- >>> bin_and(True, True)
115
- True
116
- >>> bin_and(True, False)
117
- False
118
- >>> bin_and(False, True)
119
- False
120
- >>> bin_and(False, False)
121
- False
122
-
123
- Examples:
124
- >>> bin_and_bad(False, True)
125
- True"""
126
- if a == True and b == True:
127
- return a and b
128
- return a or b
129
-
130
-
131
- def bin_or_bad(a: bool, b: bool) ->bool:
132
- """"
133
- >>> bin_or(True, True)
134
- True
135
- >>> bin_or(True, False)
136
- True
137
- >>> bin_or(False, True)
138
- True
139
- >>> bin_or(False, False)
140
- False
141
-
142
- Examples:
143
- >>> bin_or_bad(True, True)
144
- False"""
145
- return not a | b
146
-
147
-
148
- def bit_converter_excep(num: int) ->List[int]:
149
- """>>> bit_converter_excep(30)
150
- [1, 1, 1, 1, 0]"""
151
- bs = bin(num)
152
- binary_str = bs[2:]
153
- try:
154
- return [int(digit) for digit in binary_str]
155
- except Exception as e:
156
- print(binary_str)
157
- print(bs)
158
- print(f'Invalid Literal Exception in Bit Converter: {e}')
159
- return
160
-
161
-
162
- def bit_converter(num: int) ->List[int]:
163
- """
164
- >>> bit_converter(25)
165
- [1, 1, 0, 0, 1]
166
- """
167
- binary_str: str = bin(num)[2:]
168
- print(bin(num)[2:])
169
- return [int(digit) for digit in binary_str]
170
-
171
-
172
- def half_adder(a: bool, b: bool) ->tuple:
173
- """>>> half_adder(True, True)
174
- (False, True)"""
175
- sum: bool = bin_xor(a, b)
176
- carry: bool = bin_and(a, b)
177
- return sum, carry
178
-
179
-
180
- def full_adder(a: bool, b: bool, carry_in: bool) ->tuple:
181
- """>>> full_adder(True, False, False)
182
- (True, False)"""
183
- sum1, carry = half_adder(a, b)
184
- sum2, carry_out = half_adder(sum1, carry_in)
185
- return sum2, carry or carry_out
186
-
187
-
188
- def thirty_two_bit_adder_excep(x: int, y: int) ->List[int]:
189
- """>>> thirty_two_bit_adder_excep(9, 3)
190
- None
191
-
192
- Examples:
193
- >>> thirty_two_bit_adder_excep(34, 1)
194
- None"""
195
- x_bits: List[int] = bit_converter(x)
196
- y_bits: List[int] = bit_converter(y)
197
- result: List[int] = [0] * 32
198
- carry: bool = False
199
- for i in range(32):
200
- try:
201
- sum_bit, carry = full_adder(x_bits[i], y_bits[i], carry)
202
- result[i] = sum_bit
203
- except IndexError as e:
204
- print(f'Index Out of Bounds Error In ThirtyTwoBitAdder: {e}')
205
- result = [1] * 32
206
- if carry:
207
- return OverflowError('Sum exceeds 32 bits')
20
+ def pos_or_neg(i: int):
21
+ if i > 0:
22
+ sgn = 1
23
+ else:
24
+ sgn = -1
25
+ if sgn > 0:
26
+ return 1
27
+ elif sgn < 0:
28
+ return -1
29
+ # else sgn == 0
30
+ # no return here
31
+
32
+
33
+ def int_even(x: int):
34
+ if x % 2 == 0:
35
+ return True
36
+ else:
37
+ return False
38
+
39
+ def http_code(code: int) ->str:
40
+ if code < 100 or code > 599:
41
+ return 'invalid'
42
+ elif 100 <= code < 200:
43
+ return 'informational'
44
+ elif 200 <= code < 300:
45
+ return 'success'
46
+ elif 300 <= code < 400:
47
+ return 'redirection'
48
+ elif 400 <= code < 500:
49
+ return 'client error'
50
+ else:
51
+ return 'server error'
52
+
53
+ def add_or_subtract(x: int, y: int) ->int:
54
+ result = x
55
+ if x < y:
56
+ result += y
57
+ else:
58
+ result -= y
208
59
  return result
60
+
61
+ def bin_and_bad_generated_function(a: bool, b: bool):
62
+ if a == True:
63
+ if b == True:
64
+ return True
65
+ else:
66
+ return True
67
+ else:
68
+ if b == True:
69
+ return True
70
+ else:
71
+ return False
209
72
 
210
73
 
211
- def thirty_two_bit_adder(x: int, y: int) ->List[int]:
212
- """>>> thirty_two_bit_adder(8, 45)
213
- None"""
214
- print(x.bit_length() - 1)
215
- print(y.bit_length() - 1)
216
- x_bits: List[int] = bit_converter(x)
217
- y_bits: List[int] = bit_converter(y)
218
- result: List[int] = [0] * 32
219
- carry: bool = False
220
- for i in range(32):
221
- sum_bit, carry = full_adder(x_bits[i], y_bits[i], carry)
222
- result[i] = sum_bit
223
- return result
74
+ def bin_nand_generated_function(a: bool, b: bool):
75
+ if a == True:
76
+ if b == True:
77
+ return False
78
+ else:
79
+ return True
80
+ else:
81
+ if b == True:
82
+ return True
83
+ else:
84
+ return True
224
85
 
225
86
 
226
- def thirty_two_bit_adder_excep(x: int, y: int) ->List[int]:
227
- x_bits: List[int] = bit_converter(x)
228
- y_bits: List[int] = bit_converter(y)
229
- result: List[int] = [0] * 32
230
- carry: bool = False
231
- for i in range(32):
232
- sum_bit, carry = full_adder(x_bits[i], y_bits[i], carry)
233
- result[i] = sum_bit
234
- return result
87
+ def bin_nor_generated_function(a: bool, b: bool):
88
+ if a == True:
89
+ if b == True:
90
+ return False
91
+ else:
92
+ return False
93
+ else:
94
+ if b == True:
95
+ return False
96
+ else:
97
+ return True
98
+
99
+
100
+ def bin_or_generated_function(a: bool, b: bool):
101
+ if a == True:
102
+ if b == True:
103
+ return True
104
+ else:
105
+ return True
106
+ else:
107
+ if b == True:
108
+ return True
109
+ else:
110
+ return False
111
+
112
+
113
+ def bin_or_bad_generated_function(a: bool, b: bool):
114
+ if a == True:
115
+ if b == True:
116
+ return False
117
+ else:
118
+ return False
119
+ else:
120
+ if b == True:
121
+ return False
122
+ else:
123
+ return True
124
+
125
+
126
+ def bin_xor_generated_function(a: bool, b: bool):
127
+ if a == True:
128
+ if b == True:
129
+ return False
130
+ else:
131
+ return True
132
+ else:
133
+ if b == True:
134
+ return True
135
+ else:
136
+ return False
137
+
138
+
139
+ def mux_generated_function(c1: bool, c2: bool, x0: bool, x1: bool, x2: bool, x3: bool):
140
+ if c1 == True:
141
+ if c2 == True:
142
+ if x0 == True:
143
+ if x1 == True:
144
+ if x2 == True:
145
+ if x3 == True:
146
+ return True
147
+ else:
148
+ return True
149
+ else:
150
+ if x3 == True:
151
+ return True
152
+ else:
153
+ return True
154
+ else:
155
+ if x2 == True:
156
+ if x3 == True:
157
+ return True
158
+ else:
159
+ return True
160
+ else:
161
+ if x3 == True:
162
+ return True
163
+ else:
164
+ return True
165
+ else:
166
+ if x1 == True:
167
+ if x2 == True:
168
+ if x3 == True:
169
+ return False
170
+ else:
171
+ return False
172
+ else:
173
+ if x3 == True:
174
+ return False
175
+ else:
176
+ return False
177
+ else:
178
+ if x2 == True:
179
+ if x3 == True:
180
+ return False
181
+ else:
182
+ return False
183
+ else:
184
+ if x3 == True:
185
+ return False
186
+ else:
187
+ return False
188
+ else:
189
+ if x0 == True:
190
+ if x1 == True:
191
+ if x2 == True:
192
+ if x3 == True:
193
+ return True
194
+ else:
195
+ return True
196
+ else:
197
+ if x3 == True:
198
+ return True
199
+ else:
200
+ return True
201
+ else:
202
+ if x2 == True:
203
+ if x3 == True:
204
+ return False
205
+ else:
206
+ return False
207
+ else:
208
+ if x3 == True:
209
+ return False
210
+ else:
211
+ return False
212
+ else:
213
+ if x1 == True:
214
+ if x2 == True:
215
+ if x3 == True:
216
+ return True
217
+ else:
218
+ return True
219
+ else:
220
+ if x3 == True:
221
+ return True
222
+ else:
223
+ return True
224
+ else:
225
+ if x2 == True:
226
+ if x3 == True:
227
+ return False
228
+ else:
229
+ return False
230
+ else:
231
+ if x3 == True:
232
+ return False
233
+ else:
234
+ return False
235
+ else:
236
+ if c2 == True:
237
+ if x0 == True:
238
+ if x1 == True:
239
+ if x2 == True:
240
+ if x3 == True:
241
+ return True
242
+ else:
243
+ return True
244
+ else:
245
+ if x3 == True:
246
+ return False
247
+ else:
248
+ return False
249
+ else:
250
+ if x2 == True:
251
+ if x3 == True:
252
+ return True
253
+ else:
254
+ return True
255
+ else:
256
+ if x3 == True:
257
+ return False
258
+ else:
259
+ return False
260
+ else:
261
+ if x1 == True:
262
+ if x2 == True:
263
+ if x3 == True:
264
+ return True
265
+ else:
266
+ return True
267
+ else:
268
+ if x3 == True:
269
+ return False
270
+ else:
271
+ return False
272
+ else:
273
+ if x2 == True:
274
+ if x3 == True:
275
+ return True
276
+ else:
277
+ return True
278
+ else:
279
+ if x3 == True:
280
+ return False
281
+ else:
282
+ return False
283
+ else:
284
+ if x0 == True:
285
+ if x1 == True:
286
+ if x2 == True:
287
+ if x3 == True:
288
+ return True
289
+ else:
290
+ return False
291
+ else:
292
+ if x3 == True:
293
+ return True
294
+ else:
295
+ return False
296
+ else:
297
+ if x2 == True:
298
+ if x3 == True:
299
+ return True
300
+ else:
301
+ return False
302
+ else:
303
+ if x3 == True:
304
+ return True
305
+ else:
306
+ return False
307
+ else:
308
+ if x1 == True:
309
+ if x2 == True:
310
+ if x3 == True:
311
+ return True
312
+ else:
313
+ return False
314
+ else:
315
+ if x3 == True:
316
+ return True
317
+ else:
318
+ return False
319
+ else:
320
+ if x2 == True:
321
+ if x3 == True:
322
+ return True
323
+ else:
324
+ return False
325
+ else:
326
+ if x3 == True:
327
+ return True
328
+ else:
329
+ return False
@@ -1,4 +1,3 @@
1
- import importlib
2
1
  import os
3
2
  import sys
4
3
  from argparse import Namespace
@@ -6,7 +5,10 @@ import docker
6
5
  from docker import DockerClient, client
7
6
  from docker import errors
8
7
  from docker.models.containers import Container
9
- import importlib.resources
8
+ import importlib.resources as pkg_resources
9
+ import tempfile
10
+ import shutil
11
+
10
12
  from testgen.service.logging_service import get_logger
11
13
  from testgen.service.service import Service
12
14
 
@@ -134,7 +136,6 @@ class DockerController:
134
136
  print(f"Docker args: {docker_args}")
135
137
  print(f"Project root: {project_root}")
136
138
 
137
-
138
139
  return docker_client.containers.run(
139
140
  image=image_name,
140
141
  command=["testgenie"] + docker_args,
@@ -192,23 +193,23 @@ class DockerController:
192
193
  return False
193
194
 
194
195
  def get_dockerfile_path(self) -> str:
195
- print("Get dockerfile path")
196
+ # First, try local development path
196
197
  local_dockerfile = os.path.join(os.path.dirname(__file__), "docker", "Dockerfile")
197
- print(f"Checking local path: {local_dockerfile}")
198
198
  if os.path.exists(local_dockerfile):
199
+ self.debug(f"Found local Dockerfile at: {local_dockerfile}")
199
200
  return local_dockerfile
200
201
 
201
202
  # If not found locally, try inside installed package
202
203
  try:
203
- print("With importlib.resources")
204
- with importlib.resources.path('testgen.docker', 'Dockerfile') as dockerfile_path:
205
- print(f"Checking package path: {dockerfile_path}")
206
- if dockerfile_path.exists():
207
- return str(dockerfile_path)
204
+ dockerfile_resource = pkg_resources.files('testgen').joinpath('docker/Dockerfile')
205
+ if dockerfile_resource.is_file():
206
+ self.debug(f"Found package-installed Dockerfile at: {dockerfile_resource}")
207
+ return str(dockerfile_resource)
208
208
  except Exception as e:
209
209
  print(f"Error locating Dockerfile in package resources: {e}")
210
210
 
211
- raise FileNotFoundError("Dockerfile not found in local project or package.")
211
+ print("Dockerfile not found in local project or package.")
212
+ sys.exit(1)
212
213
 
213
214
  @staticmethod
214
215
  def is_inside_docker() -> bool:
@@ -155,7 +155,14 @@ class Service:
155
155
 
156
156
  try:
157
157
  if self.test_format == UNITTEST_FORMAT:
158
- self.execute_and_store_unittest(file_path_to_use, test_file)
158
+ subprocess.run(["python", "-m", "coverage", "run", "--source=.", "-m", "unittest", test_file], check=True)
159
+ result = subprocess.run(
160
+ ["python", "-m", "coverage", "report", file_path_to_use],
161
+ check=True,
162
+ capture_output=True,
163
+ text=True
164
+ )
165
+ coverage_output = result.stdout
159
166
  elif self.test_format == PYTEST_FORMAT:
160
167
  self.execute_and_store_pytest(test_file)
161
168
  elif self.test_format == DOCTEST_FORMAT:
@@ -457,8 +464,8 @@ class Service:
457
464
  loader = unittest.TestLoader()
458
465
  self.logger.debug(f"Discovering tests in: {os.path.dirname(file_path_to_use)} with pattern: {os.path.basename(test_file)}")
459
466
  test_module = os.path.relpath(test_file,
460
- start=os.getcwd())
461
- test_module = test_module.replace("/", ".").replace("\\", ".").rstrip(".py")
467
+ start=os.getcwd()) # Get relative path from the current working directory
468
+ test_module = test_module.replace("/", ".").replace("\\", ".").rstrip(".py") # Convert to module name
462
469
  if test_module.startswith("."):
463
470
  test_module = test_module[1:] # Remove leading dot if present
464
471
  self.logger.debug(f"Test module: {test_module}")
testgen/testgen.db CHANGED
Binary file