Skip to content

Commit

Permalink
fix win tests
Browse files Browse the repository at this point in the history
  • Loading branch information
xvik committed Mar 29, 2024
1 parent 3c34ef2 commit 8c19951
Show file tree
Hide file tree
Showing 4 changed files with 185 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)")
Expand All @@ -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)")
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 """
Expand Down
162 changes: 162 additions & 0 deletions src/test/groovy/ru/vyarus/gradle/plugin/python/StatsWinKitTest.groovy
Original file line number Diff line number Diff line change
@@ -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)""")
}
}

0 comments on commit 8c19951

Please sign in to comment.