testgenie-py 0.3.0__py3-none-any.whl → 0.3.2__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.
@@ -56,7 +56,6 @@ class ASTAnalyzer(TestCaseAnalyzerStrategy, ABC):
56
56
  generated_file = function_metadata.filename
57
57
  module = testgen.util.file_utils.load_module(generated_file)
58
58
 
59
- # Check if we're dealing with a class
60
59
  if function_metadata.class_name:
61
60
  cls = getattr(module, function_metadata.class_name)
62
61
  instance = cls()
@@ -46,6 +46,10 @@ class CLIController:
46
46
  print(f"Querying database for file: {args.file_path}")
47
47
  self.service.query_test_file_data(args.file_path)
48
48
  return
49
+
50
+ if args.coverage:
51
+ self.service.get_coverage(args.file_path)
52
+ return
49
53
 
50
54
  running_in_docker = os.environ.get("RUNNING_IN_DOCKER") is not None
51
55
  if running_in_docker:
@@ -159,6 +163,11 @@ class CLIController:
159
163
  type=str,
160
164
  help="Path to log file (if not specified, logs will only go to console)"
161
165
  )
166
+ parser.add_argument(
167
+ "-c", "--coverage",
168
+ action="store_true",
169
+ help="Run coverage analysis on the generated tests"
170
+ )
162
171
  return parser
163
172
 
164
173
  def set_test_format(self, args: argparse.Namespace):
@@ -35,12 +35,22 @@ class DockerController:
35
35
 
36
36
  # Check if Docker image exists, build it if not
37
37
  image_name = "testgen-runner"
38
- # If args.safe is set to false it means the image was not found and the system will try to run_locally
39
38
  self.get_image(docker_client, image_name, project_root)
40
39
  if not self.args.safe:
41
40
  self.logger.info("Docker image not found. Running locally...")
42
41
  return False
43
42
 
43
+ src_path = os.path.abspath(args.file_path)
44
+ dest_path = os.path.join(project_root, os.path.basename(src_path))
45
+ try:
46
+ shutil.copy(src_path, dest_path)
47
+ print(f"Copied file from {src_path} to {dest_path}")
48
+ self.logger.debug(f"Copied file from {src_path} to {dest_path}")
49
+ except Exception as e:
50
+ print(f"Failed to copy file: {e}")
51
+ self.logger.error(f"Failed to copy file: {e}")
52
+ sys.exit(1)
53
+
44
54
  docker_args = [args.file_path] + [arg for arg in sys.argv[2:] if arg != "--safe"]
45
55
  docker_args[0] = f"/controller/testgen/code_to_test/{os.path.basename(docker_args[0])}"
46
56
 
@@ -9,7 +9,6 @@ class DocTestGenerator(TestGenerator):
9
9
  def __init__(self, generator_context: GeneratorContext):
10
10
  super().__init__(generator_context)
11
11
 
12
- # Implementing abstract methods from TestGenerator
13
12
  def generate_test_header(self):
14
13
  pass
15
14
 
@@ -8,6 +8,8 @@ import sqlite3
8
8
  import sys
9
9
  import time
10
10
  import subprocess
11
+
12
+ import coverage
11
13
  import testgen.util.coverage_utils as coverage_utils
12
14
  from types import ModuleType
13
15
  from typing import List
@@ -163,6 +165,7 @@ class Service:
163
165
  text=True
164
166
  )
165
167
  coverage_output = result.stdout
168
+ print(coverage_output)
166
169
  elif self.test_format == PYTEST_FORMAT:
167
170
  self.execute_and_store_pytest(test_file)
168
171
  elif self.test_format == DOCTEST_FORMAT:
@@ -312,6 +315,36 @@ class Service:
312
315
  """Create an analysis context for the given file."""
313
316
  return self.analysis_service.create_analysis_context(filepath)
314
317
 
318
+ def get_coverage(self, file_path: str):
319
+ """
320
+ Use the coverage library to calculate and print the coverage for the specified Python file.
321
+ Dynamically determine the source directory based on the file being tested.
322
+ """
323
+ # Dynamically determine the source directory
324
+ source_dir = os.path.dirname(file_path)
325
+ cov = coverage.Coverage(source=[source_dir]) # Use the directory of the file as the source
326
+ cov.start()
327
+
328
+ try:
329
+ # Dynamically import and execute the specified file
330
+ file_name = os.path.basename(file_path)
331
+ module_name = file_name.rstrip(".py")
332
+ spec = importlib.util.spec_from_file_location(module_name, file_path)
333
+ module = importlib.util.module_from_spec(spec)
334
+ spec.loader.exec_module(module)
335
+
336
+ except Exception as e:
337
+ print(f"Error while executing the file: {e}")
338
+ return
339
+
340
+ finally:
341
+ cov.stop()
342
+ cov.save()
343
+
344
+ # Report the coverage
345
+ print(f"Coverage report for {file_path}:")
346
+ cov.report(file=sys.stdout)
347
+
315
348
  @staticmethod
316
349
  def wait_for_file(file_path, retries=5, delay=1):
317
350
  """Wait for the generated file to appear."""
testgen/testgen.db CHANGED
Binary file
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: testgenie-py
3
- Version: 0.3.0
3
+ Version: 0.3.2
4
4
  Summary: Automated unit test generation tool for Python.
5
5
  Author: cjseitz
6
6
  Author-email: charlesjseitz@gmail.com
@@ -1,7 +1,6 @@
1
- testgen/.coverage,sha256=Cp0ihR5Imuuiso9j7j71iuvxJfMY6aeVWNHee--RrXA,69632
2
1
  testgen/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
2
  testgen/analyzer/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
- testgen/analyzer/ast_analyzer.py,sha256=fUtrJQsgnKeSKqKaXSO_ZsY_uQr2aPeyTQP9ToyFEg4,6886
3
+ testgen/analyzer/ast_analyzer.py,sha256=y4ipJ59RfgJnhT_T1ZJP-Px3JINJovkPWMj7UpID3Ak,6824
5
4
  testgen/analyzer/contracts/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
5
  testgen/analyzer/contracts/contract.py,sha256=6rNYJOy_2GrOhGtaXTDIOX6pTEOqo856FxG0yTc8amI,369
7
6
  testgen/analyzer/contracts/no_exception_contract.py,sha256=rTWTuu5XKmvzBPD6yNAqiNehk9lbWn_Z8zFj-_djZ_w,512
@@ -11,21 +10,13 @@ testgen/analyzer/random_feedback_analyzer.py,sha256=hDcNIWE4BFtsoyXHWyxcC1qeq7y9
11
10
  testgen/analyzer/reinforcement_analyzer.py,sha256=U6W7g-xDFS_P0aqxjPRnaXjGp2gOC9TMdfWaetFV7eE,3568
12
11
  testgen/analyzer/test_case_analyzer.py,sha256=0qLcRKOrQ4Uyh1ZMecVTkY9bWjNnx7OridigNyjfUk4,1620
13
12
  testgen/analyzer/test_case_analyzer_context.py,sha256=7umDPHBjoTaCRvZOdNynpnWsr14Gy0E2hpMBPK8mz3Q,2128
14
- testgen/code_to_test/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
15
- testgen/code_to_test/boolean.py,sha256=RM2byJDKFTx1FFrxnPG_uZWb24OcOH20Uh-D1Z-yPcE,3373
16
- testgen/code_to_test/calculator.py,sha256=j7lw21BYg_vxaQVCrjOlhQOpObjSe5gu9xzthmdGphk,830
17
- testgen/code_to_test/code_to_fuzz.py,sha256=ZmASYCtvqfW-x70ynjy0o7iA9WLVbvLuf2n2K1fPE9Y,9188
18
- testgen/code_to_test/code_to_fuzz_lite.py,sha256=EjS4GB5klnJrvZIDDpS9iIt0iZETVJI0ez9DmihMiYc,10429
19
- testgen/code_to_test/decisions.py,sha256=ZiW-EF1yTOWeQVZ7Xh0oIPHK2NSNPUzVxCY0E2GbYvQ,1376
20
- testgen/code_to_test/math_utils.py,sha256=FqPQz5-e1oklzGyTVYNO8JMKDg5ob8z05VOlpKfKvvw,853
21
- testgen/code_to_test/sample_code_bin.py,sha256=kMvV_-oFeAkxUmDx41Pw0iTTmMG1pvX31TezXPWMOkE,4225
22
13
  testgen/controller/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
23
- testgen/controller/cli_controller.py,sha256=A3TsJQT20UI2TlBqC7SyI8TG0n1vP_Itd1K8TRoD3ps,8735
24
- testgen/controller/docker_controller.py,sha256=M6Q_tiAGX8j4lH1NLUFMTCreKXmoKTEpgo60z-KWVRg,8343
14
+ testgen/controller/cli_controller.py,sha256=DGPAt370TTMurL8gLKrVsl1yAP64a5OvgBBuBqhHX4I,9011
15
+ testgen/controller/docker_controller.py,sha256=YRC-q6NIofwW5IQrgTU3Td2pz5P735thDNd1W3TGI0k,8720
25
16
  testgen/docker/Dockerfile,sha256=6mutzP0ZkVueuvMLCOy2bsyGxWjLHU-cq7RFkuC8r5Y,781
26
17
  testgen/generator/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
27
18
  testgen/generator/code_generator.py,sha256=-Nh5Jt4my29YWA_LKWn98I4jvDA-fNi6AGuw-vJhRV0,3171
28
- testgen/generator/doctest_generator.py,sha256=Dkaf2l72ENk1mqNP3WkOnIY-iqrTHh-443AWtxzRWGY,8806
19
+ testgen/generator/doctest_generator.py,sha256=B9I-nw7G7ubcx51XLOl1kiOEL0YW0aDuCAKebqfkRRI,8751
29
20
  testgen/generator/generator.py,sha256=9M9zg8DO0uU5W5s9hsz2oPCL7bz7sAD087M5TYottSs,2007
30
21
  testgen/generator/pytest_generator.py,sha256=ZjQKPHlizFK2yx9WabAxkW9sM-xa64d08IIQibnvwuk,3369
31
22
  testgen/generator/test_generator.py,sha256=D2Y3DaWH4fdIc5_9Xrznrkm0urFfhpYxuhL81M7RRaw,710
@@ -50,13 +41,11 @@ testgen/service/analysis_service.py,sha256=uPoPJFLh4Imf5y_Zd8pX9zxRijr-D0K0WV22Y
50
41
  testgen/service/cfg_service.py,sha256=Czr91D5AHVq38yPKyhZDjM5jMObGPvY0yPE-PxNVBYM,2326
51
42
  testgen/service/generator_service.py,sha256=3JCWRlg5UKNhKRG9VXIycDFmuYKsRTzEmhmtlxroWAc,8088
52
43
  testgen/service/logging_service.py,sha256=tCv9LHL1gUScQQp34_iYoUxfCFzLRtFG_DXRsJ73SjA,3189
53
- testgen/service/service.py,sha256=tZz6IDsR7FjK53G9In0Bq1RlQtp2SXgcslJJ7Tmhj4I,21220
44
+ testgen/service/service.py,sha256=dhRvc-wzdn8uXozZTAx4qBVm7n48GOPue7AQ-ptMANk,22406
54
45
  testgen/sqlite/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
55
46
  testgen/sqlite/db.py,sha256=RUt88ndT4CQRo9aZzLGXPHRK1iw0LyDEGnoWlOLzKGM,2390
56
47
  testgen/sqlite/db_service.py,sha256=F2ug_FBrYOQtJwM2cMkvQrTS54_VhWGDAHXndnTi-c8,9768
57
- testgen/testgen.db,sha256=Q70k6dPV651fhLhlYzN79KlCZD8zJexy7Cn7zGDIKHo,49152
58
- testgen/tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
59
- testgen/tests/test_code_to_fuzz.py,sha256=lShIQgyb1qIElcsbUZ8pLLJB6dY1KVAA_Q76Aks6Dvg,8696
48
+ testgen/testgen.db,sha256=kXuNHy5rz2mmm9EQOgmhJDqHxbHZysBtc_8xlnMqxRw,53248
60
49
  testgen/tree/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
61
50
  testgen/tree/node.py,sha256=ONJtbACShN4yNj1X-UslFRgLyBP6mrbg7qZr3c6dWyA,165
62
51
  testgen/tree/tree_utils.py,sha256=gT7jucky6_GWVOlDI6jpv6RMeWCkntGOHIYLvHxD85k,2122
@@ -72,7 +61,7 @@ testgen/util/z3_utils/branch_condition.py,sha256=N9FNR-iJmxIC62NpDQNVZ1OP14rXXqY
72
61
  testgen/util/z3_utils/constraint_extractor.py,sha256=RXJLpmk6dAvHZ27839VXKXNtdy9St1F-17-pSEFu4bM,1285
73
62
  testgen/util/z3_utils/variable_finder.py,sha256=dUh3F9_L_BDMz1ybiGss09LLcM_egbitgj0FT5Nh9u4,245
74
63
  testgen/util/z3_utils/z3_test_case.py,sha256=yF4oJOrXMLzOwDUqXdoeg83MOTl3pvc_lYaZcS01CuQ,4983
75
- testgenie_py-0.3.0.dist-info/METADATA,sha256=_z3mECZ_M5D3bTWvzG3zE3Qow3GnUP9yyqEIrhaax70,4350
76
- testgenie_py-0.3.0.dist-info/WHEEL,sha256=fGIA9gx4Qxk2KDKeNJCbOEwSrmLtjWCwzBz351GyrPQ,88
77
- testgenie_py-0.3.0.dist-info/entry_points.txt,sha256=OUN4GqB4zHlHWwWGjwIPbur4E_ZqQgkeeqaCLhzRZgg,47
78
- testgenie_py-0.3.0.dist-info/RECORD,,
64
+ testgenie_py-0.3.2.dist-info/METADATA,sha256=m1oMD-i_FbjvMwQMpuQs-G7ID6SOv8ZxsK8OAUyS4Ew,4350
65
+ testgenie_py-0.3.2.dist-info/WHEEL,sha256=fGIA9gx4Qxk2KDKeNJCbOEwSrmLtjWCwzBz351GyrPQ,88
66
+ testgenie_py-0.3.2.dist-info/entry_points.txt,sha256=OUN4GqB4zHlHWwWGjwIPbur4E_ZqQgkeeqaCLhzRZgg,47
67
+ testgenie_py-0.3.2.dist-info/RECORD,,
testgen/.coverage DELETED
Binary file
File without changes
@@ -1,146 +0,0 @@
1
- from typing import List
2
-
3
-
4
- def bin_and(a: bool, b: bool) ->bool:
5
- """
6
- >>> bin_and(True, False)
7
- False
8
-
9
- >>> bin_and(False, True)
10
- False
11
-
12
- >>> bin_and(False, False)
13
- False
14
-
15
- >>> bin_and(True, True)
16
- True
17
- """
18
- if a == True:
19
- if b == True:
20
- return True
21
- else:
22
- return False
23
- else:
24
- return False
25
-
26
-
27
- def bin_xor(a: bool, b: bool) ->bool:
28
- """
29
- >>> bin_xor(True, True)
30
- False
31
-
32
- >>> bin_xor(True, False)
33
- True
34
-
35
- >>> bin_xor(False, False)
36
- False
37
-
38
- >>> bin_xor(False, True)
39
- True
40
- """
41
- if a == True:
42
- if b == True:
43
- return False
44
- else:
45
- return True
46
- elif b == True:
47
- return True
48
- else:
49
- return False
50
-
51
-
52
- def status_flags(active: bool, verified: bool, admin: bool) ->str:
53
- """
54
- >>> status_flags(False, False, False)
55
- 'inactive'
56
-
57
- >>> status_flags(False, False, True)
58
- 'admin-unverified'
59
-
60
- >>> status_flags(True, True, False)
61
- 'user-verified'
62
-
63
- >>> status_flags(True, True, True)
64
- 'admin-verified'
65
-
66
- >>> status_flags(True, False, False)
67
- 'user-unverified'
68
-
69
- >>> status_flags(False, True, True)
70
- 'admin-verified'
71
-
72
- >>> status_flags(False, True, False)
73
- 'inactive'
74
-
75
- >>> status_flags(True, False, True)
76
- 'admin-unverified'
77
- """
78
- if admin:
79
- if verified:
80
- return 'admin-verified'
81
- else:
82
- return 'admin-unverified'
83
- elif active:
84
- if verified:
85
- return 'user-verified'
86
- else:
87
- return 'user-unverified'
88
- else:
89
- return 'inactive'
90
-
91
-
92
- """def half_adder(a: bool, b: bool) ->tuple:
93
- sum: bool = bin_xor(a, b)
94
- carry: bool = bin_and(a, b)
95
- return sum, carry
96
-
97
-
98
- def full_adder(a: bool, b: bool, carry_in: bool) ->tuple:
99
- sum1, carry = half_adder(a, b)
100
- sum2, carry_out = half_adder(sum1, carry_in)
101
- return sum2, carry or carry_out
102
-
103
-
104
- def thirty_two_bit_adder_excep(x: int, y: int) ->List[int]:
105
- x_bits: List[int] = bit_converter(x)
106
- y_bits: List[int] = bit_converter(y)
107
- result: List[int] = [0] * 32
108
- carry: bool = False
109
- for i in range(32):
110
- try:
111
- sum_bit, carry = full_adder(x_bits[i], y_bits[i], carry)
112
- result[i] = sum_bit
113
- except IndexError as e:
114
- print(f'Index Out of Bounds Error In ThirtyTwoBitAdder: {e}')
115
- result = [1] * 32
116
- if carry:
117
- return OverflowError('Sum exceeds 32 bits')
118
- return result
119
-
120
-
121
- def thirty_two_bit_adder(x: int, y: int) ->List[int]:
122
- print(x.bit_length() - 1)
123
- print(y.bit_length() - 1)
124
- x_bits: List[int] = bit_converter(x)
125
- y_bits: List[int] = bit_converter(y)
126
- result: List[int] = [0] * 32
127
- carry: bool = False
128
- for i in range(32):
129
- sum_bit, carry = full_adder(x_bits[i], y_bits[i], carry)
130
- result[i] = sum_bit
131
- return result
132
-
133
- def bit_converter(num: int) ->List[int]:
134
- binary_str: str = bin(num)[2:]
135
- print(bin(num)[2:])
136
- return [int(digit) for digit in binary_str]
137
-
138
- def thirty_two_bit_adder_excep(x: int, y: int) ->List[int]:
139
- x_bits: List[int] = bit_converter(x)
140
- y_bits: List[int] = bit_converter(y)
141
- result: List[int] = [0] * 32
142
- carry: bool = False
143
- for i in range(32):
144
- sum_bit, carry = full_adder(x_bits[i], y_bits[i], carry)
145
- result[i] = sum_bit
146
- return result"""
@@ -1,29 +0,0 @@
1
- class AdvancedCalculator:
2
-
3
- def evaluate(self, a: int, b: int, op: str) ->(int | float | str):
4
- """>>> AdvancedCalculator().evaluate(16, 56, 'abc')
5
- 'invalid'"""
6
- if op == 'add':
7
- return a + b
8
- elif op == 'sub':
9
- return a - b
10
- elif op == 'mul':
11
- return a * b
12
- elif op == 'div':
13
- if b == 0:
14
- return 'undefined'
15
- return a / b
16
- else:
17
- return 'invalid'
18
-
19
- def is_in_range(self, val: float) ->str:
20
- """>>> AdvancedCalculator().is_in_range(0.4023417704905361)
21
- 'fractional'"""
22
- if val < 0.0:
23
- return 'below zero'
24
- elif 0.0 <= val < 1.0:
25
- return 'fractional'
26
- elif 1.0 <= val <= 100.0:
27
- return 'valid'
28
- else:
29
- return 'out of range'