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

Side by Side Diff: vpython/wheel/wheel_test.go

Issue 2700273002: vpython: Add wheel parsing/management package. (Closed)
Patch Set: rebase, 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/wheel/wheel.go ('k') | no next file » | 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 wheel
6
7 import (
8 "fmt"
9 "io/ioutil"
10 "path/filepath"
11 "testing"
12
13 "github.com/luci/luci-go/vpython/filesystem/testfs"
14
15 . "github.com/luci/luci-go/common/testing/assertions"
16 . "github.com/smartystreets/goconvey/convey"
17 )
18
19 var (
20 wheelMarkupSafe = Name{
21 Distribution: "MarkupSafe",
22 Version: "0.23",
23 BuildTag: "0",
24 PythonTag: "cp27",
25 ABITag: "none",
26 PlatformTag: "macosx_10_9_intel",
27 }
28 wheelSimpleJSON = Name{
29 Distribution: "simplejson",
30 Version: "3.6.5",
31 BuildTag: "1337",
32 PythonTag: "cp27",
33 ABITag: "none",
34 PlatformTag: "none",
35 }
36 wheelCryptography = Name{
37 Distribution: "cryptography",
38 Version: "1.4",
39 BuildTag: "1",
40 PythonTag: "cp27",
41 ABITag: "cp27m",
42 PlatformTag: "macosx_10_10_intel",
43 }
44 )
45
46 func TestName(t *testing.T) {
47 t.Parallel()
48
49 var successes = []struct {
50 v string
51 exp Name
52 }{
53 {"MarkupSafe-0.23-0-cp27-none-macosx_10_9_intel.whl", Name{
54 Distribution: "MarkupSafe",
55 Version: "0.23",
56 BuildTag: "0",
57 PythonTag: "cp27",
58 ABITag: "none",
59 PlatformTag: "macosx_10_9_intel",
60 }},
61 {"cryptography-1.4-1-cp27-cp27m-macosx_10_10_intel.whl", Name{
62 Distribution: "cryptography",
63 Version: "1.4",
64 BuildTag: "1",
65 PythonTag: "cp27",
66 ABITag: "cp27m",
67 PlatformTag: "macosx_10_10_intel",
68 }},
69 {"numpy-1.11.0-0_b6a34c03e3a3cea974e4c0000788d4edc7d43a36-cp27-c p27m-" +
70 "macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64. macosx_10_10_intel.macosx_10_10_x86_64.whl",
71 Name{
72 Distribution: "numpy",
73 Version: "1.11.0",
74 BuildTag: "0_b6a34c03e3a3cea974e4c0000788d4e dc7d43a36",
75 PythonTag: "cp27",
76 ABITag: "cp27m",
77 PlatformTag: "macosx_10_6_intel.macosx_10_9_int el.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64",
78 }},
79 {"simplejson-3.6.5-1337-cp27-none-none.whl", Name{
80 Distribution: "simplejson",
81 Version: "3.6.5",
82 BuildTag: "1337",
83 PythonTag: "cp27",
84 ABITag: "none",
85 PlatformTag: "none",
86 }},
87 {"nobuildtag-1.2.3-cp27-none-none.whl", Name{
88 Distribution: "nobuildtag",
89 Version: "1.2.3",
90 BuildTag: "",
91 PythonTag: "cp27",
92 ABITag: "none",
93 PlatformTag: "none",
94 }},
95 }
96
97 var failures = []struct {
98 v string
99 err string
100 }{
101 {"foo-bar-baz-qux-quux", "missing .whl suffix"},
102 {"foo-bar-baz-qux.whl", "unknown number of segments"},
103 }
104
105 Convey(`Testing wheel name parsing`, t, func() {
106 for _, tc := range successes {
107 Convey(fmt.Sprintf(`Success: %s`, tc.v), func() {
108 wn, err := ParseName(tc.v)
109 So(err, ShouldBeNil)
110 So(wn, ShouldResemble, tc.exp)
111 So(wn.String(), ShouldEqual, tc.v)
112 })
113 }
114
115 for _, tc := range failures {
116 Convey(fmt.Sprintf(`Failure: %s`, tc.v), func() {
117 _, err := ParseName(tc.v)
118 So(err, ShouldErrLike, tc.err)
119 })
120 }
121 })
122 }
123
124 func TestScanDir(t *testing.T) {
125 t.Parallel()
126
127 Convey(`Testing ScanDir`, t, testfs.MustWithTempDir(t, "TestScanDir", fu nc(tdir string) {
128 mustBuild := func(layout map[string]string) {
129 if err := testfs.Build(tdir, layout); err != nil {
130 panic(err)
131 }
132 }
133
134 mustBuild(map[string]string{
135 "junk.bin": "",
136 "junk": "",
137 wheelMarkupSafe.String(): "",
138 wheelSimpleJSON.String(): "",
139 wheelCryptography.String() + "/": "", // Directories sho uld be ignored.
140 })
141
142 Convey(`With no malformed wheels, picks up wheel names.`, func() {
143 wheels, err := ScanDir(tdir)
144 So(err, ShouldBeNil)
145 So(wheels, ShouldResemble, []Name{wheelMarkupSafe, wheel SimpleJSON})
146 })
147
148 Convey(`With a malformed wheel name, fails.`, func() {
149 mustBuild(map[string]string{
150 "malformed-thing.whl": "",
151 })
152
153 _, err := ScanDir(tdir)
154 So(err, ShouldErrLike, "failed to parse wheel")
155 })
156 }))
157 }
158
159 func TestWriteRequirementsFile(t *testing.T) {
160 t.Parallel()
161
162 Convey(`Can write a requirements file.`, t,
163 testfs.MustWithTempDir(t, "TestWriteRequirementsFile", func(tdir string) {
164 similarSimpleJSON := wheelSimpleJSON
165 similarSimpleJSON.ABITag = "some_other_abi"
166
167 req := filepath.Join(tdir, "requirements.txt")
168 err := WriteRequirementsFile(req, []Name{
169 wheelMarkupSafe,
170 wheelSimpleJSON,
171 similarSimpleJSON,
172 wheelCryptography})
173 So(err, ShouldBeNil)
174
175 content, err := ioutil.ReadFile(req)
176 So(err, ShouldBeNil)
177 So(content, ShouldResemble, []byte(""+
178 "MarkupSafe==0.23\n"+
179 "simplejson==3.6.5\n"+
180 "cryptography==1.4\n"))
181 }))
182 }
OLDNEW
« no previous file with comments | « vpython/wheel/wheel.go ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698