testgenie-py 0.2.0__py3-none-any.whl → 0.2.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.
Files changed (33) hide show
  1. testgen/analyzer/random_feedback_analyzer.py +344 -114
  2. testgen/controller/cli_controller.py +5 -10
  3. testgen/controller/docker_controller.py +56 -38
  4. testgen/docker/Dockerfile +19 -10
  5. testgen/generated_samplecodebin.py +545 -0
  6. testgen/generator/code_generator.py +36 -18
  7. testgen/reinforcement/environment.py +1 -1
  8. testgen/service/generator_service.py +16 -1
  9. testgen/service/service.py +124 -32
  10. testgen/sqlite/db_service.py +22 -2
  11. testgen/util/coverage_utils.py +35 -0
  12. testgen/util/file_utils.py +40 -10
  13. testgen/util/randomizer.py +29 -12
  14. {testgenie_py-0.2.0.dist-info → testgenie_py-0.2.2.dist-info}/METADATA +2 -1
  15. {testgenie_py-0.2.0.dist-info → testgenie_py-0.2.2.dist-info}/RECORD +17 -32
  16. testgen/.coverage +0 -0
  17. testgen/code_to_test/__init__.py +0 -0
  18. testgen/code_to_test/boolean.py +0 -146
  19. testgen/code_to_test/calculator.py +0 -29
  20. testgen/code_to_test/code_to_fuzz.py +0 -234
  21. testgen/code_to_test/code_to_fuzz_lite.py +0 -397
  22. testgen/code_to_test/decisions.py +0 -57
  23. testgen/code_to_test/math_utils.py +0 -47
  24. testgen/code_to_test/no_types.py +0 -35
  25. testgen/code_to_test/sample_code_bin.py +0 -141
  26. testgen/docker/poetry.lock +0 -599
  27. testgen/docker/pyproject.toml +0 -29
  28. testgen/q_table/global_q_table.json +0 -1
  29. testgen/testgen.db +0 -0
  30. testgen/tests/__init__.py +0 -0
  31. testgen/tests/test_decisions.py +0 -195
  32. {testgenie_py-0.2.0.dist-info → testgenie_py-0.2.2.dist-info}/WHEEL +0 -0
  33. {testgenie_py-0.2.0.dist-info → testgenie_py-0.2.2.dist-info}/entry_points.txt +0 -0
@@ -30,6 +30,7 @@ class DockerController:
30
30
  def run_in_docker(self, project_root: str, docker_client: DockerClient, args: Namespace) -> bool:
31
31
  self.args = args
32
32
  self.debug_mode = True if args.debug else False
33
+
33
34
  os.environ["RUNNING_IN_DOCKER"] = "1"
34
35
 
35
36
  # Check if Docker image exists, build it if not
@@ -41,6 +42,7 @@ class DockerController:
41
42
  return False
42
43
 
43
44
  docker_args = [args.file_path] + [arg for arg in sys.argv[2:] if arg != "--safe"]
45
+ docker_args[0] = f"/controller/testgen/code_to_test/{os.path.basename(docker_args[0])}"
44
46
 
45
47
  # Run the container with the same arguments
46
48
  try:
@@ -51,48 +53,44 @@ class DockerController:
51
53
  logs_output = self.get_logs(container)
52
54
  self.debug(logs_output)
53
55
 
54
- try:
55
- # Create the target directory if it doesn't exist
56
- if args.output is None:
57
- target_path = os.path.join(os.getcwd(), 'tests')
58
- else:
59
- target_path = args.output
60
- os.makedirs(target_path, exist_ok=True)
56
+ except Exception as e:
57
+ print(f"Error running container: {e}")
58
+ sys.exit(1)
61
59
 
62
- self.debug(f"SERVICE target path after logs: {target_path}")
60
+ # Create the target directory if it doesn't exist
61
+ if args.output is None:
62
+ target_path = os.path.join(os.getcwd(), 'tests')
63
+ else:
64
+ target_path = args.output
65
+ os.makedirs(target_path, exist_ok=True)
63
66
 
64
- test_cases = self.service.parse_test_cases_from_logs(logs_output)
67
+ self.debug(f"SERVICE target path after logs: {target_path}")
65
68
 
66
- print(f"Extracted {len(test_cases)} test cases from container.")
69
+ test_cases = self.service.parse_test_cases_from_logs(logs_output)
67
70
 
68
- file_path = os.path.abspath(args.file_path)
69
- self.debug(f"Filepath in CLI CONTROLLER: {file_path}")
70
- self.service.set_file_path(file_path)
71
+ print(f"Extracted {len(test_cases)} test cases from container.")
71
72
 
72
- if args.test_format == "pytest":
73
- self.service.set_test_generator_format(PYTEST_FORMAT)
74
- elif args.test_format == "doctest":
75
- self.service.set_test_generator_format(DOCTEST_FORMAT)
76
- else:
77
- self.service.set_test_generator_format(UNITTEST_FORMAT)
73
+ file_path = os.path.abspath(args.file_path)
74
+ self.debug(f"Filepath in CLI CONTROLLER: {file_path}")
75
+ self.service.set_file_path(file_path)
78
76
 
79
- test_file = self.service.generate_test_file(test_cases, target_path)
80
- print(f"Unit tests saved to: {test_file}")
77
+ if args.test_format == "pytest":
78
+ self.service.set_test_generator_format(PYTEST_FORMAT)
79
+ elif args.test_format == "doctest":
80
+ self.service.set_test_generator_format(DOCTEST_FORMAT)
81
+ else:
82
+ self.service.set_test_generator_format(UNITTEST_FORMAT)
81
83
 
82
- if not args.generate_only:
83
- print("Running coverage...")
84
- self.service.run_coverage(test_file)
85
-
86
- # Add explicit return True here
87
- return True
84
+ test_file = self.service.generate_test_file(test_cases, target_path)
85
+ print(f"Unit tests saved to: {test_file}")
88
86
 
89
- except Exception as e:
90
- print(f"Error running container: {e}")
91
- sys.exit(1)
87
+ if not args.generate_only:
88
+ print("Running coverage...")
89
+ self.service.run_coverage(test_file)
90
+
91
+ # Add explicit return True here
92
+ return True
92
93
 
93
- except Exception as e:
94
- print(f"Error running container: {e}")
95
- sys.exit(1)
96
94
 
97
95
  def get_image(self, docker_client: DockerClient, image_name: str, project_root: str):
98
96
  try:
@@ -129,15 +127,30 @@ class DockerController:
129
127
  # Create Docker-specific environment variables
130
128
  docker_env = {
131
129
  "RUNNING_IN_DOCKER": "1",
132
- "PYTHONPATH": "/controller",
133
- "COVERAGE_FILE": "/tmp/.coverage", # Move coverage file to /tmp
134
- "DB_PATH": "/tmp/testgen.db" # Move DB to /tmp
130
+ "PYTHONPATH": "/controller"
135
131
  }
136
132
 
133
+ # Join arguments with proper escaping
134
+ args_str = ' '.join(f'"{arg}"' for arg in docker_args)
135
+
136
+ print(f"Docker args: {docker_args}")
137
+ print(f"Project root: {project_root}")
138
+
139
+ # Debug command to find file and then run testgenie with args
140
+ debug_cmd = f'find /controller -type f -name "*.py" | grep -i boolean || echo "File not found"; ' \
141
+ f'ls -la /controller; ' \
142
+ f'testgenie /controller/testgen/code_to_test/boolean.py --test-mode=fuzz --test-format=pytest'
143
+
137
144
  return docker_client.containers.run(
138
145
  image=image_name,
139
- command=["python", "-m", "testgen.main"] + docker_args,
140
- volumes={project_root: {"bind": "/controller", "mode": "rw"}},
146
+ command=["sh", "-c", debug_cmd],
147
+ volumes={
148
+ os.path.abspath(project_root): {
149
+ "bind": "/controller",
150
+ "mode": "rw"
151
+ }
152
+ },
153
+ working_dir="/controller",
141
154
  environment=docker_env,
142
155
  detach=True,
143
156
  remove=True,
@@ -203,6 +216,11 @@ class DockerController:
203
216
  print("Dockerfile not found in local project or package.")
204
217
  sys.exit(1)
205
218
 
219
+ @staticmethod
220
+ def is_inside_docker() -> bool:
221
+ """Check if the current process is running inside a Docker container."""
222
+ return os.environ.get("RUNNING_IN_DOCKER") in ("1", "true", "True")
223
+
206
224
  def debug(self, message: str):
207
225
  """Log debug message"""
208
226
  if self.debug_mode:
testgen/docker/Dockerfile CHANGED
@@ -1,22 +1,31 @@
1
+ # Use Python 3.10 image
1
2
  FROM python:3.10
2
3
 
3
- RUN apt-get update && apt-get install -y curl build-essential
4
+ # Install system dependencies
5
+ RUN apt-get update && apt-get install -y \
6
+ build-essential \
7
+ graphviz \
8
+ libgraphviz-dev \
9
+ pkg-config \
10
+ curl
4
11
 
5
- RUN curl -sSL https://install.python-poetry.org | python3 - \
6
- && ln -s /root/.local/bin/poetry /usr/local/bin/poetry
12
+ # Install Poetry (optional, in case you ever need it)
13
+ RUN curl -sSL https://install.python-poetry.org | python3 - && \
14
+ ln -s /root/.local/bin/poetry /usr/local/bin/poetry
7
15
 
16
+ # Set environment variables
8
17
  ENV POETRY_VIRTUALENVS_CREATE=false \
9
18
  PYTHONUNBUFFERED=1 \
10
19
  RUNNING_IN_DOCKER=true
11
20
 
12
- WORKDIR /controller
21
+ # Install your package from PyPI
22
+ RUN python3 -m pip install --no-cache-dir testgenie-py
13
23
 
14
- # Copy poetry files
15
- COPY . .
24
+ # Set a working directory (where your code will be mounted at runtime)
25
+ WORKDIR /controller
16
26
 
27
+ # Set up PYTHONPATH
17
28
  ENV PYTHONPATH=/controller:/controller/testgen
18
29
 
19
- RUN poetry install --no-root
20
-
21
- # Entrypoint (Can be overridden by Docker SDK in Python)
22
- CMD ["poetry", "run", "python", "-m", "testgen.main"]
30
+ # Default command
31
+ CMD ["testgenie"]