Skip to content

Commit 4d9f00b

Browse files
committed
move python task environment tests to separate test
1 parent b9805d2 commit 4d9f00b

File tree

2 files changed

+89
-51
lines changed

2 files changed

+89
-51
lines changed
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
package ru.vyarus.gradle.plugin.python.task
2+
3+
import org.gradle.testkit.runner.BuildResult
4+
import org.gradle.testkit.runner.TaskOutcome
5+
import ru.vyarus.gradle.plugin.python.AbstractKitTest
6+
7+
/**
8+
* @author Vyacheslav Rusakov
9+
* @since 17.03.2020
10+
*/
11+
class PythonTaskEnvironmentKitTest extends AbstractKitTest {
12+
13+
def "Check env vars"() {
14+
setup:
15+
build """
16+
plugins {
17+
id 'ru.vyarus.use-python'
18+
}
19+
20+
task sample(type: PythonTask) {
21+
command = "-c \\"import os;print('variables: '+os.getenv('some', 'null')+' '+os.getenv('foo', 'null'))\\""
22+
environment 'some', 1
23+
environment(['foo': 'bar'])
24+
}
25+
"""
26+
27+
when: "run task"
28+
debug()
29+
BuildResult result = run('sample')
30+
31+
then: "variables visible"
32+
result.task(':sample').outcome == TaskOutcome.SUCCESS
33+
result.output.contains('variables: 1 bar')
34+
}
35+
36+
37+
def "Check python see system variables"() {
38+
setup:
39+
build """
40+
plugins {
41+
id 'ru.vyarus.use-python'
42+
}
43+
44+
assert System.getenv('some') == 'foo'
45+
46+
task sample(type: PythonTask) {
47+
command = "-c \\"import os;print('variables: '+os.getenv('some', 'null'))\\""
48+
}
49+
"""
50+
51+
when: "run task"
52+
def env = new HashMap(System.getenv())
53+
env.put('some', 'foo')
54+
BuildResult result = gradle('sample')
55+
.withEnvironment(env)
56+
.build()
57+
58+
then: "system variable visible"
59+
result.task(':sample').outcome == TaskOutcome.SUCCESS
60+
result.output.contains('variables: foo')
61+
}
62+
63+
def "Check python dont see system variables after override"() {
64+
setup:
65+
build """
66+
plugins {
67+
id 'ru.vyarus.use-python'
68+
}
69+
70+
assert System.getenv('some') == 'foo'
71+
72+
task sample(type: PythonTask) {
73+
command = "-c \\"import os;print('variables: '+os.getenv('some', 'null'))\\""
74+
environment 'bar', 1
75+
}
76+
"""
77+
78+
when: "run task"
79+
def env = new HashMap(System.getenv())
80+
env.put('some', 'foo')
81+
BuildResult result = gradle('sample')
82+
.withEnvironment(env)
83+
.build()
84+
85+
then: "setting variable doesn't hide system vars"
86+
result.task(':sample').outcome == TaskOutcome.SUCCESS
87+
result.output.contains('variables: foo')
88+
}
89+
}

src/test/groovy/ru/vyarus/gradle/plugin/python/task/PythonTaskKitTest.groovy

Lines changed: 0 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -183,55 +183,4 @@ class PythonTaskKitTest extends AbstractKitTest {
183183
result.output =~ /\[python] python(3)? sample.py/
184184
result.output.contains('\t sample')
185185
}
186-
187-
188-
def "Check env vars"() {
189-
setup:
190-
build """
191-
plugins {
192-
id 'ru.vyarus.use-python'
193-
}
194-
195-
task sample(type: PythonTask) {
196-
command = "-c \\"import os;print('variables: '+os.getenv('some', 'null')+' '+os.getenv('foo', 'null'))\\""
197-
environment 'some', 1
198-
environment(['foo': 'bar'])
199-
}
200-
"""
201-
202-
when: "run task"
203-
debug()
204-
BuildResult result = run('sample')
205-
206-
then: "executed"
207-
result.task(':sample').outcome == TaskOutcome.SUCCESS
208-
result.output.contains('variables: 1 bar')
209-
}
210-
211-
212-
def "Check python see system variables"() {
213-
setup:
214-
build """
215-
plugins {
216-
id 'ru.vyarus.use-python'
217-
}
218-
219-
assert System.getenv('some') == 'foo'
220-
221-
task sample(type: PythonTask) {
222-
command = "-c \\"import os;print('variables: '+os.getenv('some', 'null'))\\""
223-
}
224-
"""
225-
226-
when: "run task"
227-
def env = new HashMap(System.getenv())
228-
env.put('some', 'foo')
229-
BuildResult result = gradle('sample')
230-
.withEnvironment(env)
231-
.build()
232-
233-
then: "executed"
234-
result.task(':sample').outcome == TaskOutcome.SUCCESS
235-
result.output.contains('variables: foo')
236-
}
237186
}

0 commit comments

Comments
 (0)