Skip to content

Conversation

@tamarinvs19
Copy link
Collaborator

@tamarinvs19 tamarinvs19 commented Dec 19, 2022

Description

Fix bug with database path in python module coverage. Now we create database in temporary directory with other python files.

Note: See #1542

Fixes #1478

Type of Change

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

Manual Scenario

See #1478 steps 1-8 with plugin from this build

Expected result: generated tests, for example:

import sys
sys.path.append('..')
import builtins
import types
import sample
import unittest


class TestTopLevelFunctions(unittest.TestCase):
    # region Test suites for executable sample.print_hi
    
    # region
    
    def test_print_hi(self):
        actual = sample.print_hi((1 << 100))
        
        self.assertEqual(None, actual)
    
    def test_print_hi_throws_t(self):
        sample.print_hi(str(b'\xf0\xa3\x91\x96', 'utf-8'))
        
        # raises builtins.UnicodeEncodeError
    # endregion
    
    # endregion
    
    # region Test suites for executable sample.div
    
    # region
    
    def test_div(self):
        actual = sample.div(1, 1)
        
        self.assertEqual(1.0, actual)
    # endregion
    
    # endregion

Checklist (remove irrelevant options):

This is the author self-check list

  • The change followed the style guidelines of the UTBot project
  • Self-review of the code is passed
  • The change contains enough commentaries, particularly in hard-to-understand areas
  • New documentation is provided or existed one is altered
  • No new warnings
  • New tests have been added
  • All tests pass locally with my changes

@tamarinvs19 tamarinvs19 added ctg-bug Issue is a bug lang-python Issue is related to python support labels Dec 19, 2022
@tyuldashev
Copy link
Collaborator

Unfortunately it still doesn't work, it looks the same as before - just hangs during generation. It seems that this version has no verbose logging, so I'm not sure if it's the same error (problem with sql-light db file) or another one.

@tyuldashev
Copy link
Collaborator

Errors from the log:

2022-12-20 13:26:26,441 [ 133425]   INFO - STDOUT - | UtBot - PythonEvaluation          | Start evaluation div with [1, 0.0]
2022-12-20 13:26:26,441 [ 133425]   INFO - STDOUT - | UtBot - PythonEvaluation          | Evaluation with arguments [1, 0.0] finished; Exit value: 1; Stdout: ; Stderr:   File "C:\Users\T00814~1\AppData\Local\Temp\UTBot\python-test-generation-0368468099035101053\51_run_div.py", line 8
2022-12-20 13:26:26,443 [ 133427]   INFO - STDOUT -     run_calculate_function_value('C:\Users\T00814~1\AppData\Local\Temp\UTBot\python-test-generation-0368468099035101053\50_coverage_db_div',
2022-12-20 13:26:26,443 [ 133427]   INFO - STDOUT -                                                                                                                                            ^
2022-12-20 13:26:26,443 [ 133427]   INFO - STDOUT - SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape
2022-12-20 13:26:26,446 [ 133430]   INFO - STDOUT - | UtBot - PythonEvaluation          | Start evaluation div with [4294967296, 0.0]
2022-12-20 13:26:26,448 [ 133432]   INFO - STDOUT - | UtBot - PythonEvaluation          | Evaluation with arguments [4294967296, 0.0] finished; Exit value: 1; Stdout: ; Stderr:   File "C:\Users\T00814~1\AppData\Local\Temp\UTBot\python-test-generation-0368468099035101053\54_run_div.py", line 8
2022-12-20 13:26:26,448 [ 133432]   INFO - STDOUT -     run_calculate_function_value('C:\Users\T00814~1\AppData\Local\Temp\UTBot\python-test-generation-0368468099035101053\53_coverage_db_div',
2022-12-20 13:26:26,448 [ 133432]   INFO - STDOUT -                                                                                                                                            ^

@tamarinvs19
Copy link
Collaborator Author

Errors from the log:

2022-12-20 13:26:26,441 [ 133425]   INFO - STDOUT - | UtBot - PythonEvaluation          | Start evaluation div with [1, 0.0]
2022-12-20 13:26:26,441 [ 133425]   INFO - STDOUT - | UtBot - PythonEvaluation          | Evaluation with arguments [1, 0.0] finished; Exit value: 1; Stdout: ; Stderr:   File "C:\Users\T00814~1\AppData\Local\Temp\UTBot\python-test-generation-0368468099035101053\51_run_div.py", line 8
2022-12-20 13:26:26,443 [ 133427]   INFO - STDOUT -     run_calculate_function_value('C:\Users\T00814~1\AppData\Local\Temp\UTBot\python-test-generation-0368468099035101053\50_coverage_db_div',
2022-12-20 13:26:26,443 [ 133427]   INFO - STDOUT -                                                                                                                                            ^
2022-12-20 13:26:26,443 [ 133427]   INFO - STDOUT - SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape
2022-12-20 13:26:26,446 [ 133430]   INFO - STDOUT - | UtBot - PythonEvaluation          | Start evaluation div with [4294967296, 0.0]
2022-12-20 13:26:26,448 [ 133432]   INFO - STDOUT - | UtBot - PythonEvaluation          | Evaluation with arguments [4294967296, 0.0] finished; Exit value: 1; Stdout: ; Stderr:   File "C:\Users\T00814~1\AppData\Local\Temp\UTBot\python-test-generation-0368468099035101053\54_run_div.py", line 8
2022-12-20 13:26:26,448 [ 133432]   INFO - STDOUT -     run_calculate_function_value('C:\Users\T00814~1\AppData\Local\Temp\UTBot\python-test-generation-0368468099035101053\53_coverage_db_div',
2022-12-20 13:26:26,448 [ 133432]   INFO - STDOUT -                                                                                                                                            ^

I fixed this problem and start plugin building https://github.com/UnitTestBot/UTBotJava/actions/runs/3741539443

@tyuldashev
Copy link
Collaborator

It generates tests now, but not always can cleanup temp directories after execution:

java.nio.file.DirectoryNotEmptyException: C:\Users\T00814~1\AppData\Local\Temp\UTBot\python-test-generation-24799704321262215703
	at java.base/sun.nio.fs.WindowsFileSystemProvider.implDelete(WindowsFileSystemProvider.java:272)
	at java.base/sun.nio.fs.AbstractFileSystemProvider.delete(AbstractFileSystemProvider.java:105)
	at java.base/java.nio.file.Files.delete(Files.java:1152)
	at org.utbot.python.utils.TemporaryFileManager$setup$1.invoke(TemporaryFileManager.kt:15)
	at org.utbot.python.utils.TemporaryFileManager$setup$1.invoke(TemporaryFileManager.kt:15)
	at org.utbot.python.utils.Cleaner$addFunction$newClean$1.invoke(Cleaner.kt:9)
	at org.utbot.python.utils.Cleaner$addFunction$newClean$1.invoke(Cleaner.kt:8)
	at org.utbot.python.utils.Cleaner$addFunction$newClean$1.invoke(Cleaner.kt:10)
	at org.utbot.python.utils.Cleaner$addFunction$newClean$1.invoke(Cleaner.kt:8)
	at org.utbot.python.utils.Cleaner$addFunction$newClean$1.invoke(Cleaner.kt:10)
	at org.utbot.python.utils.Cleaner$addFunction$newClean$1.invoke(Cleaner.kt:8)
	at org.utbot.python.utils.Cleaner$addFunction$newClean$1.invoke(Cleaner.kt:10)
	at org.utbot.python.utils.Cleaner$addFunction$newClean$1.invoke(Cleaner.kt:8)
	at org.utbot.python.utils.Cleaner$addFunction$newClean$1.invoke(Cleaner.kt:10)
	at org.utbot.python.utils.Cleaner$addFunction$newClean$1.invoke(Cleaner.kt:8)
	at org.utbot.python.utils.Cleaner$addFunction$newClean$1.invoke(Cleaner.kt:10)
	at org.utbot.python.utils.Cleaner$addFunction$newClean$1.invoke(Cleaner.kt:8)
	at org.utbot.python.utils.Cleaner.doCleaning(Cleaner.kt:20)
	at org.utbot.python.PythonTestGenerationProcessor.processTestGeneration(PythonTestGenerationProcessor.kt:210)
	at org.utbot.python.PythonTestGenerationProcessor.processTestGeneration$default(PythonTestGenerationProcessor.kt:34)
	at org.utbot.intellij.plugin.language.python.PythonDialogProcessor$createTests$1.run(PythonDialogProcessor.kt:135)
	at com.intellij.openapi.progress.impl.CoreProgressManager.startTask(CoreProgressManager.java:442)
	at com.intellij.openapi.progress.impl.ProgressManagerImpl.startTask(ProgressManagerImpl.java:114)
	at com.intellij.openapi.progress.impl.CoreProgressManager.lambda$runProcessWithProgressAsynchronously$5(CoreProgressManager.java:493)
	at com.intellij.openapi.progress.impl.ProgressRunner.lambda$submit$3(ProgressRunner.java:252)
	at com.intellij.openapi.progress.impl.CoreProgressManager.lambda$runProcess$2(CoreProgressManager.java:188)
	at com.intellij.openapi.progress.impl.CoreProgressManager.lambda$executeProcessUnderProgress$12(CoreProgressManager.java:608)
	at com.intellij.openapi.progress.impl.CoreProgressManager.registerIndicatorAndRun(CoreProgressManager.java:683)
	at com.intellij.openapi.progress.impl.CoreProgressManager.computeUnderProgress(CoreProgressManager.java:639)
	at com.intellij.openapi.progress.impl.CoreProgressManager.executeProcessUnderProgress(CoreProgressManager.java:607)
	at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:60)
	at com.intellij.openapi.progress.impl.CoreProgressManager.runProcess(CoreProgressManager.java:175)
	at com.intellij.openapi.progress.impl.ProgressRunner.lambda$submit$4(ProgressRunner.java:252)
	at java.base/java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1768)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
	at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1$1.run(Executors.java:702)
	at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1$1.run(Executors.java:699)
	at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
	at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1.run(Executors.java:699)
	at java.base/java.lang.Thread.run(Thread.java:833)

@tamarinvs19
Copy link
Collaborator Author

tamarinvs19 commented Dec 21, 2022

New build with fixed last bug https://github.com/UnitTestBot/UTBotJava/actions/runs/3747621097

@tamarinvs19 tamarinvs19 marked this pull request as draft December 21, 2022 09:25
@tamarinvs19
Copy link
Collaborator Author

@tamarinvs19 tamarinvs19 marked this pull request as ready for review December 21, 2022 11:40
@tamarinvs19 tamarinvs19 merged commit 44bc8cd into main Dec 21, 2022
@tamarinvs19 tamarinvs19 deleted the tamarinvs19/fix_python_coverage_database branch December 21, 2022 12:41
denis-fokin pushed a commit that referenced this pull request Dec 21, 2022
@alisevych alisevych modified the milestone: 2023.03 Release Mar 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ctg-bug Issue is a bug lang-python Issue is related to python support

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Python test generation error

5 participants