Closed BergLucas closed 3 months ago
Describe the bug Pynguin crashes when generating assertions for subclasses of the float type.
To Reproduce Steps to reproduce the behaviour:
import numpy as np
def foo(x: float) -> np.float64: return np.float64(x)
4. Use the following command line arguments to Pynguin:
--module-name --project-path --output-path --assertion-generation SIMPLE
5. Give the error (stack trace, etc) you are encountering:
╭─────────────────────────────── Traceback (most recent call last) ────────────────────────────────╮ │ /home/lucas/Documents/GitHub/pynguin-for-ML-libraries/pynguin/src/pynguin/testcase/execution.py: │ │ 2248 in execute │ │ │ │ 2245 │ │ │ │ _LOGGER.warning("Experienced timeout from test-case execution") │ │ 2246 │ │ │ else: │ │ 2247 │ │ │ │ try: │ │ ❱ 2248 │ │ │ │ │ result = return_queue.get(block=False) │ │ 2249 │ │ │ │ except Empty as ex: │ │ 2250 │ │ │ │ │ _LOGGER.error("Finished thread did not return a result.") │ │ 2251 │ │ │ │ │ raise RuntimeError("Bug in Pynguin!") from ex │ │ │ │ /home/lucas/.conda/envs/pynguin-for-ML-libraries/lib/python3.10/queue.py:168 in get │ │ │ │ 165 │ │ with self.not_empty: │ │ 166 │ │ │ if not block: │ │ 167 │ │ │ │ if not self._qsize(): │ │ ❱ 168 │ │ │ │ │ raise Empty │ │ 169 │ │ │ elif timeout is None: │ │ 170 │ │ │ │ while not self._qsize(): │ │ 171 │ │ │ │ │ self.not_empty.wait() │ ╰──────────────────────────────────────────────────────────────────────────────────────────────────╯ Empty
The above exception was the direct cause of the following exception:
╭─────────────────────────────── Traceback (most recent call last) ────────────────────────────────╮ │ /home/lucas/.conda/envs/pynguin-for-ML-libraries/bin/pynguin:8 in │ │ │ │ 5 from pynguin.cli import main │ │ 6 if name == 'main': │ │ 7 │ sys.argv[0] = re.sub(r'(-script.pyw|.exe)?$', '', sys.argv[0]) │ │ ❱ 8 │ sys.exit(main()) │ │ 9 │ │ │ │ /home/lucas/Documents/GitHub/pynguin-for-ML-libraries/pynguin/src/pynguin/cli.py:193 in main │ │ │ │ 190 │ set_configuration(parsed.config) │ │ 191 │ if console is not None: │ │ 192 │ │ with console.status("Running Pynguin..."): │ │ ❱ 193 │ │ │ return run_pynguin().value │ │ 194 │ else: │ │ 195 │ │ return run_pynguin().value │ │ 196 │ │ │ │ /home/lucas/Documents/GitHub/pynguin-for-ML-libraries/pynguin/src/pynguin/generator.py:108 in │ │ run_pynguin │ │ │ │ 105 │ """ │ │ 106 │ try: │ │ 107 │ │ _LOGGER.info("Start Pynguin Test Generation…") │ │ ❱ 108 │ │ return _run() │ │ 109 │ finally: │ │ 110 │ │ _LOGGER.info("Stop Pynguin Test Generation…") │ │ 111 │ │ │ │ /home/lucas/Documents/GitHub/pynguin-for-ML-libraries/pynguin/src/pynguin/generator.py:533 in │ │ _run │ │ │ │ 530 │ │ │ 531 │ _track_search_metrics(algorithm, generation_result, coverage_metrics) │ │ 532 │ _remove_statements_after_exceptions(generation_result) │ │ ❱ 533 │ _generate_assertions(executor, generation_result) │ │ 534 │ tracked_metrics = _track_final_metrics( │ │ 535 │ │ algorithm, executor, generation_result, constant_provider │ │ 536 │ ) │ │ │ │ /home/lucas/Documents/GitHub/pynguin-for-ML-libraries/pynguin/src/pynguin/generator.py:604 in │ │ _generate_assertions │ │ │ │ 601 │ │ │ ) │ │ 602 │ │ else: │ │ 603 │ │ │ generator = ag.AssertionGenerator(executor) │ │ ❱ 604 │ │ generation_result.accept(generator) │ │ 605 │ │ 606 │ │ 607 def _track_search_metrics( │ │ │ │ /home/lucas/Documents/GitHub/pynguin-for-ML-libraries/pynguin/src/pynguin/ga/testsuitechromosome │ │ .py:187 in accept │ │ │ │ 184 │ │ │ self.changed = True │ │ 185 │ │ │ 186 │ def accept(self, visitor: cv.ChromosomeVisitor) -> None: # noqa: D102 │ │ ❱ 187 │ │ visitor.visit_test_suite_chromosome(self) │ │ 188 │ │ │ 189 │ def eq(self, other: object) -> bool: │ │ 190 │ │ if self is other: │ │ │ │ /home/lucas/Documents/GitHub/pynguin-for-ML-libraries/pynguin/src/pynguin/assertion/assertiongen │ │ erator.py:72 in visit_test_suite_chromosome │ │ │ │ 69 │ def visit_test_suite_chromosome( # noqa: D102 │ │ 70 │ │ self, chromosome: tsc.TestSuiteChromosome │ │ 71 │ ) -> None: │ │ ❱ 72 │ │ self._add_assertions( │ │ 73 │ │ │ [chrom.test_case for chrom in chromosome.test_case_chromosomes] │ │ 74 │ │ ) │ │ 75 │ │ │ │ /home/lucas/Documents/GitHub/pynguin-for-ML-libraries/pynguin/src/pynguin/assertion/assertiongen │ │ erator.py:99 in _add_assertions │ │ │ │ 96 │ │ │ │ randomness.RNG.shuffle(shuffled_copy) │ │ 97 │ │ │ │ for test in shuffled_copy: │ │ 98 │ │ │ │ │ self.__remove_non_holding_assertions( │ │ ❱ 99 │ │ │ │ │ │ test, self._plain_executor.execute(test) │ │ 100 │ │ │ │ │ ) │ │ 101 │ │ │ 102 │ @staticmethod │ │ │ │ /home/lucas/Documents/GitHub/pynguin-for-ML-libraries/pynguin/src/pynguin/testcase/execution.py: │ │ 2251 in execute │ │ │ │ 2248 │ │ │ │ │ result = return_queue.get(block=False) │ │ 2249 │ │ │ │ except Empty as ex: │ │ 2250 │ │ │ │ │ _LOGGER.error("Finished thread did not return a result.") │ │ ❱ 2251 │ │ │ │ │ raise RuntimeError("Bug in Pynguin!") from ex │ │ 2252 │ │ self._after_test_case_execution_outside_thread(test_case, result) │ │ 2253 │ │ return result │ │ 2254 │ ╰──────────────────────────────────────────────────────────────────────────────────────────────────╯ RuntimeError: Bug in Pynguin!
**Expected behavior** Pynguin should generate assertions successfully. **Software Version (please complete the following information):** - OS: Fedora 39 - Python version: 3.10 - Pynguin Version: 0.36.0
Fixed with Pynguin 0.37.0, thanks for the fix!
Describe the bug Pynguin crashes when generating assertions for subclasses of the float type.
To Reproduce Steps to reproduce the behaviour:
def foo(x: float) -> np.float64: return np.float64(x)
--module-name
--project-path
--output-path
--assertion-generation SIMPLE
╭─────────────────────────────── Traceback (most recent call last) ────────────────────────────────╮ │ /home/lucas/Documents/GitHub/pynguin-for-ML-libraries/pynguin/src/pynguin/testcase/execution.py: │ │ 2248 in execute │ │ │ │ 2245 │ │ │ │ _LOGGER.warning("Experienced timeout from test-case execution") │ │ 2246 │ │ │ else: │ │ 2247 │ │ │ │ try: │ │ ❱ 2248 │ │ │ │ │ result = return_queue.get(block=False) │ │ 2249 │ │ │ │ except Empty as ex: │ │ 2250 │ │ │ │ │ _LOGGER.error("Finished thread did not return a result.") │ │ 2251 │ │ │ │ │ raise RuntimeError("Bug in Pynguin!") from ex │ │ │ │ /home/lucas/.conda/envs/pynguin-for-ML-libraries/lib/python3.10/queue.py:168 in get │ │ │ │ 165 │ │ with self.not_empty: │ │ 166 │ │ │ if not block: │ │ 167 │ │ │ │ if not self._qsize(): │ │ ❱ 168 │ │ │ │ │ raise Empty │ │ 169 │ │ │ elif timeout is None: │ │ 170 │ │ │ │ while not self._qsize(): │ │ 171 │ │ │ │ │ self.not_empty.wait() │ ╰──────────────────────────────────────────────────────────────────────────────────────────────────╯ Empty
The above exception was the direct cause of the following exception:
╭─────────────────────────────── Traceback (most recent call last) ────────────────────────────────╮ │ /home/lucas/.conda/envs/pynguin-for-ML-libraries/bin/pynguin:8 in │
│ │
│ 5 from pynguin.cli import main │
│ 6 if name == 'main': │
│ 7 │ sys.argv[0] = re.sub(r'(-script.pyw|.exe)?$', '', sys.argv[0]) │
│ ❱ 8 │ sys.exit(main()) │
│ 9 │
│ │
│ /home/lucas/Documents/GitHub/pynguin-for-ML-libraries/pynguin/src/pynguin/cli.py:193 in main │
│ │
│ 190 │ set_configuration(parsed.config) │
│ 191 │ if console is not None: │
│ 192 │ │ with console.status("Running Pynguin..."): │
│ ❱ 193 │ │ │ return run_pynguin().value │
│ 194 │ else: │
│ 195 │ │ return run_pynguin().value │
│ 196 │
│ │
│ /home/lucas/Documents/GitHub/pynguin-for-ML-libraries/pynguin/src/pynguin/generator.py:108 in │
│ run_pynguin │
│ │
│ 105 │ """ │
│ 106 │ try: │
│ 107 │ │ _LOGGER.info("Start Pynguin Test Generation…") │
│ ❱ 108 │ │ return _run() │
│ 109 │ finally: │
│ 110 │ │ _LOGGER.info("Stop Pynguin Test Generation…") │
│ 111 │
│ │
│ /home/lucas/Documents/GitHub/pynguin-for-ML-libraries/pynguin/src/pynguin/generator.py:533 in │
│ _run │
│ │
│ 530 │ │
│ 531 │ _track_search_metrics(algorithm, generation_result, coverage_metrics) │
│ 532 │ _remove_statements_after_exceptions(generation_result) │
│ ❱ 533 │ _generate_assertions(executor, generation_result) │
│ 534 │ tracked_metrics = _track_final_metrics( │
│ 535 │ │ algorithm, executor, generation_result, constant_provider │
│ 536 │ ) │
│ │
│ /home/lucas/Documents/GitHub/pynguin-for-ML-libraries/pynguin/src/pynguin/generator.py:604 in │
│ _generate_assertions │
│ │
│ 601 │ │ │ ) │
│ 602 │ │ else: │
│ 603 │ │ │ generator = ag.AssertionGenerator(executor) │
│ ❱ 604 │ │ generation_result.accept(generator) │
│ 605 │
│ 606 │
│ 607 def _track_search_metrics( │
│ │
│ /home/lucas/Documents/GitHub/pynguin-for-ML-libraries/pynguin/src/pynguin/ga/testsuitechromosome │
│ .py:187 in accept │
│ │
│ 184 │ │ │ self.changed = True │
│ 185 │ │
│ 186 │ def accept(self, visitor: cv.ChromosomeVisitor) -> None: # noqa: D102 │
│ ❱ 187 │ │ visitor.visit_test_suite_chromosome(self) │
│ 188 │ │
│ 189 │ def eq(self, other: object) -> bool: │
│ 190 │ │ if self is other: │
│ │
│ /home/lucas/Documents/GitHub/pynguin-for-ML-libraries/pynguin/src/pynguin/assertion/assertiongen │
│ erator.py:72 in visit_test_suite_chromosome │
│ │
│ 69 │ def visit_test_suite_chromosome( # noqa: D102 │
│ 70 │ │ self, chromosome: tsc.TestSuiteChromosome │
│ 71 │ ) -> None: │
│ ❱ 72 │ │ self._add_assertions( │
│ 73 │ │ │ [chrom.test_case for chrom in chromosome.test_case_chromosomes] │
│ 74 │ │ ) │
│ 75 │
│ │
│ /home/lucas/Documents/GitHub/pynguin-for-ML-libraries/pynguin/src/pynguin/assertion/assertiongen │
│ erator.py:99 in _add_assertions │
│ │
│ 96 │ │ │ │ randomness.RNG.shuffle(shuffled_copy) │
│ 97 │ │ │ │ for test in shuffled_copy: │
│ 98 │ │ │ │ │ self.__remove_non_holding_assertions( │
│ ❱ 99 │ │ │ │ │ │ test, self._plain_executor.execute(test) │
│ 100 │ │ │ │ │ ) │
│ 101 │ │
│ 102 │ @staticmethod │
│ │
│ /home/lucas/Documents/GitHub/pynguin-for-ML-libraries/pynguin/src/pynguin/testcase/execution.py: │
│ 2251 in execute │
│ │
│ 2248 │ │ │ │ │ result = return_queue.get(block=False) │
│ 2249 │ │ │ │ except Empty as ex: │
│ 2250 │ │ │ │ │ _LOGGER.error("Finished thread did not return a result.") │
│ ❱ 2251 │ │ │ │ │ raise RuntimeError("Bug in Pynguin!") from ex │
│ 2252 │ │ self._after_test_case_execution_outside_thread(test_case, result) │
│ 2253 │ │ return result │
│ 2254 │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
RuntimeError: Bug in Pynguin!