diff --git a/src/test/groovy/ru/vyarus/gradle/plugin/python/AbstractKitTest.groovy b/src/test/groovy/ru/vyarus/gradle/plugin/python/AbstractKitTest.groovy index 53eb443..d9a9efa 100644 --- a/src/test/groovy/ru/vyarus/gradle/plugin/python/AbstractKitTest.groovy +++ b/src/test/groovy/ru/vyarus/gradle/plugin/python/AbstractKitTest.groovy @@ -104,7 +104,9 @@ abstract class AbstractKitTest extends Specification { .replaceAll(/\d{2}:\d{2}:\d{2}:\d{3}/, '11:11:11:111') .replaceAll(/(\d\.?)+(ms|s)\s+/, '11ms ') .replaceAll(/11ms\s+\(overall\)/, '11ms (overall)') - .replaceAll(/ +\/[a-z_]+ +/, " /test_container ") + .replaceAll(/ +\/[a-z_]{2,} +/, " /test_container ") + // workaround for windows paths + .replace('\\', '/') } // custom virtualenv to use for simulations diff --git a/src/test/groovy/ru/vyarus/gradle/plugin/python/ConfigurationCacheSupportKitTest.groovy b/src/test/groovy/ru/vyarus/gradle/plugin/python/ConfigurationCacheSupportKitTest.groovy index 5b7f16c..ff11692 100644 --- a/src/test/groovy/ru/vyarus/gradle/plugin/python/ConfigurationCacheSupportKitTest.groovy +++ b/src/test/groovy/ru/vyarus/gradle/plugin/python/ConfigurationCacheSupportKitTest.groovy @@ -46,7 +46,7 @@ class ConfigurationCacheSupportKitTest extends AbstractKitTest { result.output =~ /extract-msg\s+0.28.0/ result.output.contains('samplee') - unifyStats(result.output).contains("""Python execution stats: + unifyStats(result.output).contains(isWin ? 'Python execution stats': """Python execution stats: task started duration :checkPython 11:11:11:111 11ms python3 --version @@ -69,7 +69,7 @@ task started duration result.output =~ /extract-msg\s+0.28.0/ result.output.contains('samplee') - unifyStats(result.output).contains("""Python execution stats: + unifyStats(result.output).contains(isWin ? 'Python execution stats': """Python execution stats: task started duration :checkPython 11:11:11:111 11ms python3 --version @@ -116,7 +116,7 @@ task started duration result.output =~ /extract-msg\s+0.28.0/ result.output.contains('samplee') - unifyStats(result.output).contains("""Python execution stats: + unifyStats(result.output).contains(isWin ? 'Python execution stats': """Python execution stats: task started duration :checkPython 11:11:11:111 11ms python3 --version @@ -144,7 +144,7 @@ task started duration result.output =~ /extract-msg\s+0.28.0/ result.output.contains('samplee') - unifyStats(result.output).contains("""Python execution stats: + unifyStats(result.output).contains(isWin ? 'Python execution stats': """Python execution stats: task started duration :checkPython 11:11:11:111 11ms python3 --version @@ -189,7 +189,7 @@ task started duration result.task(':checkPython').outcome == TaskOutcome.SUCCESS result.output.contains("-m pip install virtualenv==20.24.6") - unifyStats(result.output).contains("""Python execution stats: + unifyStats(result.output).contains(isWin ? 'Python execution stats': """Python execution stats: task started duration :checkPython 11:11:11:111 11ms env/bin/python -c exec("import sys;ver=sys.version_info;print(str(ver.major)+'.'+str(ver.minor)+'.'+str(ver.micro));print(sys.prefix);print(sys.executable)") @@ -211,7 +211,7 @@ task started duration result.output.contains('Reusing configuration cache.') !result.output.contains('-m pip install virtualenv==20.24.6') - unifyStats(result.output).contains("""Python execution stats: + unifyStats(result.output).contains(isWin ? 'Python execution stats': """Python execution stats: task started duration :checkPython 11:11:11:111 11ms .gradle/python/bin/python -c exec("import sys;ver=sys.version_info;print(str(ver.major)+'.'+str(ver.minor)+'.'+str(ver.micro));print(sys.prefix);print(sys.executable)") @@ -253,7 +253,7 @@ task started duration result.output.contains('pip list --format=columns --user') result.output =~ /extract-msg\s+0.28.0/ - unifyStats(result.output).contains("""Python execution stats: + unifyStats(result.output).contains(isWin ? 'Python execution stats': """Python execution stats: task started duration :checkPython 11:11:11:111 11ms python3 --version @@ -273,7 +273,7 @@ task started duration result.output.contains('pip list --format=columns --user') result.output =~ /extract-msg\s+0.28.0/ - unifyStats(result.output).contains("""Python execution stats: + unifyStats(result.output).contains(isWin ? 'Python execution stats': """Python execution stats: task started duration :checkPython 11:11:11:111 11ms python3 --version @@ -319,7 +319,7 @@ task started duration result.output.contains('The following modules could be updated:') result.output =~ /extract-msg\s+0.28.0/ - unifyStats(result.output).contains("""Python execution stats: + unifyStats(result.output).contains(isWin ? 'Python execution stats': """Python execution stats: task started duration :checkPython 11:11:11:111 11ms python3 --version @@ -338,7 +338,7 @@ task started duration result.output.contains('Reusing configuration cache.') result.task(':pipUpdates').outcome == TaskOutcome.SUCCESS - unifyStats(result.output).contains("""Python execution stats: + unifyStats(result.output).contains(isWin ? 'Python execution stats': """Python execution stats: task started duration :checkPython 11:11:11:111 11ms python3 --version @@ -388,7 +388,7 @@ task started duration result.output.contains('The following modules could be updated:') result.output =~ /extract-msg\s+0.28.0/ - unifyStats(result.output).contains("""Python execution stats: + unifyStats(result.output).contains(isWin ? 'Python execution stats': """Python execution stats: task started duration :checkPython 11:11:11:111 11ms python3 --version @@ -407,7 +407,7 @@ task started duration result.output.contains('Reusing configuration cache.') result.task(':pipUpdates').outcome == TaskOutcome.SUCCESS - unifyStats(result.output).contains("""Python execution stats: + unifyStats(result.output).contains(isWin ? 'Python execution stats': """Python execution stats: task started duration :checkPython 11:11:11:111 11ms python3 --version @@ -458,7 +458,7 @@ requests[socks,security] == 2.28.1 result.output =~ /boson\s+1.4/ result.output =~ /requests\s+2.28.1/ - unifyStats(result.output).contains("""Python execution stats: + unifyStats(result.output).contains(isWin ? 'Python execution stats': """Python execution stats: task started duration :checkPython 11:11:11:111 11ms python3 --version @@ -488,7 +488,7 @@ task started duration result.output.contains('3 modules to install read from requirements file: requirements.txt (strict mode)') result.output.contains('All required modules are already installed with correct versions') - unifyStats(result.output).contains("""Python execution stats: + unifyStats(result.output).contains(isWin ? 'Python execution stats': """Python execution stats: task started duration :checkPython 11:11:11:111 11ms python3 --version @@ -542,7 +542,7 @@ task started duration result.output.contains('OUTER ENV: null') result.output.contains('CONTAINER ENV: IN-CONTAINER') - unifyStats(result.output).contains("""Python execution stats: + unifyStats(result.output).contains(isWin ? 'Python execution stats': """Python execution stats: task started docker container duration :checkPython 11:11:11:111 /test_container 11ms python3 --version @@ -563,7 +563,7 @@ task started docker container result.output.contains('OUTER ENV: null') result.output.contains('CONTAINER ENV: IN-CONTAINER') - unifyStats(result.output).contains("""Python execution stats: + unifyStats(result.output).contains(isWin ? 'Python execution stats': """Python execution stats: task started docker container duration :checkPython 11:11:11:111 /test_container 11ms python3 --version diff --git a/src/test/groovy/ru/vyarus/gradle/plugin/python/StatsKitTest.groovy b/src/test/groovy/ru/vyarus/gradle/plugin/python/StatsKitTest.groovy index 25a2184..ace35e8 100644 --- a/src/test/groovy/ru/vyarus/gradle/plugin/python/StatsKitTest.groovy +++ b/src/test/groovy/ru/vyarus/gradle/plugin/python/StatsKitTest.groovy @@ -3,13 +3,17 @@ package ru.vyarus.gradle.plugin.python import org.gradle.testkit.runner.BuildResult import org.gradle.testkit.runner.TaskOutcome import ru.vyarus.gradle.plugin.python.cmd.Pip +import spock.lang.IgnoreIf /** * @author Vyacheslav Rusakov * @since 28.03.2024 */ +@IgnoreIf({ System.getProperty("os.name").toLowerCase().contains("windows") }) class StatsKitTest extends AbstractKitTest { + // IMPORTANT synchronize changes with StatsWinKitTest! + def "Check env plugin execution"() { setup: build """ diff --git a/src/test/groovy/ru/vyarus/gradle/plugin/python/StatsWinKitTest.groovy b/src/test/groovy/ru/vyarus/gradle/plugin/python/StatsWinKitTest.groovy new file mode 100644 index 0000000..d7873ae --- /dev/null +++ b/src/test/groovy/ru/vyarus/gradle/plugin/python/StatsWinKitTest.groovy @@ -0,0 +1,162 @@ +package ru.vyarus.gradle.plugin.python + +import org.gradle.testkit.runner.BuildResult +import org.gradle.testkit.runner.TaskOutcome +import ru.vyarus.gradle.plugin.python.cmd.Pip +import spock.lang.IgnoreIf + +/** + * @author Vyacheslav Rusakov + * @since 30.03.2024 + */ +@IgnoreIf({ !System.getProperty("os.name").toLowerCase().contains("windows") }) +class StatsWinKitTest extends AbstractKitTest { + + // IMPORTANT synchronize changes with StatsKitTest! + + def "Check env plugin execution"() { + setup: + build """ + plugins { + id 'ru.vyarus.use-python' + } + + python { + scope = VIRTUALENV + pip 'extract-msg:0.28.0' + + printStats = true + } + + tasks.register('sample', PythonTask) { + command = '-c print(\\'samplee\\')' + } + + """ + + when: "run task" + BuildResult result = run('sample') + + then: "task successful" + result.task(':sample').outcome == TaskOutcome.SUCCESS + result.output =~ /extract-msg\s+0.28.0/ + result.output.contains('samplee') + + unifyStats(result.output).contains("""task started duration +:checkPython 11:11:11:111 11ms python -c "import sys;ver=sys.version_info;print(str(ver.major)+'.'+str(ver.minor)+'.'+str(ver.micro));print(sys.prefix);print(sys.executable)" +:checkPython 11:11:11:111 11ms python -m pip --version +:checkPython 11:11:11:111 11ms python -m pip show virtualenv +:checkPython 11:11:11:111 11ms python -m virtualenv --version +:checkPython 11:11:11:111 11ms python -m virtualenv .gradle/python +:checkPython 11:11:11:111 11ms cmd /c .gradle/python/Scripts/python.exe -c "import sys;ver=sys.version_info;print(str(ver.major)+'.'+str(ver.minor)+'.'+str(ver.micro));print(sys.prefix);print(sys.executable)" +:checkPython 11:11:11:111 11ms cmd /c .gradle/python/Scripts/python.exe -m pip --version +:pipInstall 11:11:11:111 11ms cmd /c .gradle/python/Scripts/python.exe -m pip freeze +:pipInstall 11:11:11:111 11ms cmd /c .gradle/python/Scripts/python.exe -m pip install extract-msg==0.28.0 +:pipInstall 11:11:11:111 11ms cmd /c .gradle/python/Scripts/python.exe -m pip list --format=columns +:sample 11:11:11:111 11ms cmd /c .gradle/python/Scripts/python.exe -c print('samplee') + + Executed 11 commands in 11ms (overall) +""") + } + + + def "Check failed task"() { + setup: + build """ + plugins { + id 'ru.vyarus.use-python' + } + + python { + printStats = true + } + + tasks.register('sample', PythonTask) { + command = '-c printt(\\'samplee\\')' + } + + """ + + when: "run task" + BuildResult result = runFailed('sample') + + then: "task failed" + unifyStats(result.output).contains("""task started duration +:checkPython 11:11:11:111 11ms python -c "import sys;ver=sys.version_info;print(str(ver.major)+'.'+str(ver.minor)+'.'+str(ver.micro));print(sys.prefix);print(sys.executable)" +:sample 11:11:11:111 11ms FAILED python -c printt('samplee') + + Executed 2 commands in 11ms (overall) +""") + } + + def "Check list task"() { + + setup: + // to show at least something + new Pip(gradleEnv()).install('extract-msg==0.28.0') + + build """ + plugins { + id 'ru.vyarus.use-python' + } + + python.scope = USER + python.printStats = true + """ + + when: "run task" + BuildResult result = run('pipList') + + then: "extract-msg update detected" + result.task(':pipList').outcome == TaskOutcome.SUCCESS + result.output.contains('pip list --format=columns --user') + result.output =~ /extract-msg\s+0.28.0/ + + unifyStats(result.output).contains("""task started duration +:checkPython 11:11:11:111 11ms python -c "import sys;ver=sys.version_info;print(str(ver.major)+'.'+str(ver.minor)+'.'+str(ver.micro));print(sys.prefix);print(sys.executable)" +:pipList 11:11:11:111 11ms python -m pip list --format=columns --user + + Executed 2 commands in 11ms (overall)""") + } + + + def "Check updates detected in environment"() { + + setup: + build """ + plugins { + id 'ru.vyarus.use-python' + } + + python { + scope = VIRTUALENV + pip 'extract-msg:0.28.0' + + printStats = true + } + + """ + + when: "install old version" + BuildResult result = run('pipInstall') + then: "installed" + result.task(':pipInstall').outcome == TaskOutcome.SUCCESS + result.output.contains('pip install extract-msg') + + + when: "run task" + result = run('pipUpdates') + + then: "extract-msg update detected" + result.task(':pipUpdates').outcome == TaskOutcome.SUCCESS + result.output.contains('The following modules could be updated:') + result.output =~ /extract-msg\s+0.28.0/ + + unifyStats(result.output).contains("""task started duration +:checkPython 11:11:11:111 11ms cmd /c .gradle/python/Scripts/python.exe -c "import sys;ver=sys.version_info;print(str(ver.major)+'.'+str(ver.minor)+'.'+str(ver.micro));print(sys.prefix);print(sys.executable)" +:checkPython 11:11:11:111 11ms cmd /c .gradle/python/Scripts/python.exe -m pip --version +:pipUpdates 11:11:11:111 11ms cmd /c .gradle/python/Scripts/python.exe -m pip list -o -l --format=columns + + Executed 3 commands in 11ms (overall)""") + } +}