Skip to content

Commit

Permalink
fix stats printer test
Browse files Browse the repository at this point in the history
  • Loading branch information
xvik committed Mar 29, 2024
1 parent a2409d1 commit 0b2eaf3
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 26 deletions.
13 changes: 13 additions & 0 deletions src/test/groovy/ru/vyarus/gradle/plugin/python/AbstractTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,19 @@ abstract class AbstractTest extends Specification {
}), project.provider { false })
}

protected String unifyString(String input) {
return input
// cleanup win line break for simpler comparisons
.replace("\r", '')
}

String unifyStats(String text) {
return unifyString(text)
.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)')
}

static class ExtendedProjectBuilder {
Project root

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package ru.vyarus.gradle.plugin.python.util

import ru.vyarus.gradle.plugin.python.AbstractKitTest
import ru.vyarus.gradle.plugin.python.service.stat.PythonStat
import ru.vyarus.gradle.plugin.python.service.stat.StatsPrinter
import spock.lang.Specification

/**
* @author Vyacheslav Rusakov
* @since 28.03.2024
*/
class StatsPrinterTest extends Specification {
class StatsPrinterTest extends AbstractKitTest {

def "Print simple stats"() {
List<PythonStat> stats = []
Expand All @@ -34,14 +34,14 @@ class StatsPrinterTest extends Specification {
println res

then: "ok"
res == """
unifyStats(res) == """
Python execution stats:
task started duration
:gg 07:00:00:100 10ms something
:hh 07:00:00:120 10ms something-else
:gg 11:11:11:111 11ms something
:hh 11:11:11:111 11ms something-else
Executed 2 commands in 20ms (overall)
Executed 2 commands in 11ms (overall)
"""

}
Expand Down Expand Up @@ -80,15 +80,15 @@ task started duration
println res

then: "ok"
res == """
unifyStats(res) == """
Python execution stats:
task started docker container duration
:gg 07:00:00:100 python12 10ms something
:hh 07:00:00:120 10ms something-else
:tt 07:00:00:130 python13 10ms other
:gg 11:11:11:111 python12 11ms something
:hh 11:11:11:111 11ms something-else
:tt 11:11:11:111 python13 11ms other
Executed 3 commands in 30ms (overall)
Executed 3 commands in 11ms (overall)
"""

}
Expand Down Expand Up @@ -117,14 +117,14 @@ task started docker container
println res

then: "ok"
res == """
unifyStats(res) == """
Python execution stats:
task started duration
:gg 07:00:00:100 10ms something
:hh 07:00:00:120 10ms FAILED something-else
:gg 11:11:11:111 11ms something
:hh 11:11:11:111 11ms FAILED something-else
Executed 2 commands in 20ms (overall)
Executed 2 commands in 11ms (overall)
"""
}

Expand Down Expand Up @@ -160,15 +160,15 @@ task started duration
println res

then: "ok"
res == """
unifyStats(res) == """
Python execution stats:
task started duration
:gg 07:00:00:100 10ms something
:hh || 07:00:00:120 10ms something-else
:tt || 07:00:00:125 10ms other
:gg 11:11:11:111 11ms something
:hh || 11:11:11:111 11ms something-else
:tt || 11:11:11:111 11ms other
Executed 3 commands in 30ms (overall)
Executed 3 commands in 11ms (overall)
"""
}

Expand Down Expand Up @@ -212,16 +212,16 @@ task started duration
println res

then: "ok"
res == """
unifyStats(res) == """
Python execution stats:
task started duration
:gg 07:00:00:100 10ms something
:hh 07:00:00:120 10ms something
:tt 07:00:00:130 10ms other
:pp 07:00:00:140 10ms other
:gg 11:11:11:111 11ms something
:hh 11:11:11:111 11ms something
:tt 11:11:11:111 11ms other
:pp 11:11:11:111 11ms other
Executed 4 commands in 40ms (overall)
Executed 4 commands in 11ms (overall)
Duplicate executions:
Expand Down

0 comments on commit 0b2eaf3

Please sign in to comment.