Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(59)

Side by Side Diff: vpython/spec/load_test.go

Issue 2705623003: vpython: Add environment spec package. (Closed)
Patch Set: env to vpython, comments Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « vpython/spec/load.go ('k') | vpython/spec/spec.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2017 The LUCI Authors. All rights reserved.
2 // Use of this source code is governed under the Apache License, Version 2.0
3 // that can be found in the LICENSE file.
4
5 package spec
6
7 import (
8 "path/filepath"
9 "strings"
10 "testing"
11
12 "github.com/luci/luci-go/vpython/api/vpython"
13 "github.com/luci/luci-go/vpython/filesystem/testfs"
14
15 "github.com/golang/protobuf/proto"
16 "golang.org/x/net/context"
17
18 . "github.com/luci/luci-go/common/testing/assertions"
19 . "github.com/smartystreets/goconvey/convey"
20 )
21
22 func TestLoadForScript(t *testing.T) {
23 t.Parallel()
24
25 goodSpec := &vpython.Spec{
26 PythonVersion: "3.4.0",
27 Wheel: []*vpython.Spec_Package{
28 {Path: "foo/bar", Version: "1"},
29 {Path: "baz/qux", Version: "2"},
30 },
31 }
32 goodSpecData := proto.MarshalTextString(goodSpec)
33 badSpecData := "foo: bar"
34
35 Convey(`Test LoadForScript`, t, testfs.MustWithTempDir(t, "TestLoadForSc ript", func(tdir string) {
36 c := context.Background()
37
38 makePath := func(path string) string {
39 return filepath.Join(tdir, filepath.FromSlash(path))
40 }
41 mustBuild := func(layout map[string]string) {
42 if err := testfs.Build(tdir, layout); err != nil {
43 panic(err)
44 }
45 }
46
47 Convey(`Layout: module with a good spec file`, func() {
48 mustBuild(map[string]string{
49 "foo/bar/baz/__main__.py": "main",
50 "foo/bar/baz/__init__.py": "",
51 "foo/bar/__init__.py": "",
52 "foo/bar.vpython": goodSpecData,
53 })
54 spec, err := LoadForScript(c, makePath("foo/bar/baz"), t rue)
55 So(err, ShouldBeNil)
56 So(spec, ShouldResemble, goodSpec)
57 })
58
59 Convey(`Layout: module with a bad spec file`, func() {
60 mustBuild(map[string]string{
61 "foo/bar/baz/__main__.py": "main",
62 "foo/bar/baz/__init__.py": "",
63 "foo/bar/__init__.py": "",
64 "foo/bar.vpython": badSpecData,
65 })
66 _, err := LoadForScript(c, makePath("foo/bar/baz"), true )
67 So(err, ShouldErrLike, "failed to unmarshal vpython.Spec ")
68 })
69
70 Convey(`Layout: module with no spec file`, func() {
71 mustBuild(map[string]string{
72 "foo/bar/baz/__main__.py": "main",
73 "foo/bar/baz/__init__.py": "",
74 "foo/bar/__init__.py": "",
75 "foo/__init__.py": "",
76 })
77 spec, err := LoadForScript(c, makePath("foo/bar/baz"), t rue)
78 So(err, ShouldBeNil)
79 So(spec, ShouldBeNil)
80 })
81
82 Convey(`Layout: individual file with a good spec file`, func() {
83 mustBuild(map[string]string{
84 "pants.py": "PANTS!",
85 "pants.py.vpython": goodSpecData,
86 })
87 spec, err := LoadForScript(c, makePath("pants.py"), fals e)
88 So(err, ShouldBeNil)
89 So(spec, ShouldResemble, goodSpec)
90 })
91
92 Convey(`Layout: individual file with a bad spec file`, func() {
93 mustBuild(map[string]string{
94 "pants.py": "PANTS!",
95 "pants.py.vpython": badSpecData,
96 })
97 _, err := LoadForScript(c, makePath("pants.py"), false)
98 So(err, ShouldErrLike, "failed to unmarshal vpython.Spec ")
99 })
100
101 Convey(`Layout: individual file with no spec (inline or file)`, func() {
102 mustBuild(map[string]string{
103 "pants.py": "PANTS!",
104 })
105 spec, err := LoadForScript(c, makePath("pants.py"), fals e)
106 So(err, ShouldBeNil)
107 So(spec, ShouldBeNil)
108 })
109
110 Convey(`Layout: module with good inline spec`, func() {
111 mustBuild(map[string]string{
112 "foo/bar/baz/__main__.py": strings.Join([]string {
113 "#!/usr/bin/env vpython",
114 "",
115 "# Test file",
116 "",
117 `"""Docstring`,
118 "[VPYTHON:BEGIN]",
119 goodSpecData,
120 "[VPYTHON:END]",
121 `"""`,
122 "",
123 "# Additional content...",
124 }, "\n"),
125 })
126 spec, err := LoadForScript(c, makePath("foo/bar/baz"), t rue)
127 So(err, ShouldBeNil)
128 So(spec, ShouldResemble, goodSpec)
129 })
130
131 Convey(`Layout: individual file with good inline spec`, func() {
132 mustBuild(map[string]string{
133 "pants.py": strings.Join([]string{
134 "#!/usr/bin/env vpython",
135 "",
136 "# Test file",
137 "",
138 `"""Docstring`,
139 "[VPYTHON:BEGIN]",
140 goodSpecData,
141 "[VPYTHON:END]",
142 `"""`,
143 "",
144 "# Additional content...",
145 }, "\n"),
146 })
147 spec, err := LoadForScript(c, makePath("pants.py"), fals e)
148 So(err, ShouldBeNil)
149 So(spec, ShouldResemble, goodSpec)
150 })
151
152 Convey(`Layout: individual file with good inline spec with a pre fix`, func() {
153 specParts := strings.Split(goodSpecData, "\n")
154 for i, line := range specParts {
155 specParts[i] = strings.TrimSpace("# " + line)
156 }
157
158 mustBuild(map[string]string{
159 "pants.py": strings.Join([]string{
160 "#!/usr/bin/env vpython",
161 "",
162 "# Test file",
163 "#",
164 "# [VPYTHON:BEGIN]",
165 strings.Join(specParts, "\n"),
166 "# [VPYTHON:END]",
167 "",
168 "# Additional content...",
169 }, "\n"),
170 })
171
172 spec, err := LoadForScript(c, makePath("pants.py"), fals e)
173 So(err, ShouldBeNil)
174 So(spec, ShouldResemble, goodSpec)
175 })
176
177 Convey(`Layout: individual file with bad inline spec`, func() {
178 mustBuild(map[string]string{
179 "pants.py": strings.Join([]string{
180 "#!/usr/bin/env vpython",
181 "",
182 "# Test file",
183 "",
184 `"""Docstring`,
185 "[VPYTHON:BEGIN]",
186 badSpecData,
187 "[VPYTHON:END]",
188 `"""`,
189 "",
190 "# Additional content...",
191 }, "\n"),
192 })
193
194 _, err := LoadForScript(c, makePath("pants.py"), false)
195 So(err, ShouldErrLike, "failed to unmarshal vpython.Spec ")
196 })
197
198 Convey(`Layout: individual file with inline spec, missing end ba rrier`, func() {
199 mustBuild(map[string]string{
200 "pants.py": strings.Join([]string{
201 "#!/usr/bin/env vpython",
202 "",
203 "# Test file",
204 "",
205 `"""Docstring`,
206 "[VPYTHON:BEGIN]",
207 goodSpecData,
208 `"""`,
209 "",
210 "# Additional content...",
211 }, "\n"),
212 })
213
214 _, err := LoadForScript(c, makePath("pants.py"), false)
215 So(err, ShouldErrLike, "unterminated inline spec file")
216 })
217 }))
218 }
OLDNEW
« no previous file with comments | « vpython/spec/load.go ('k') | vpython/spec/spec.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698