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

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

Issue 2700273002: vpython: Add wheel parsing/management package. (Closed)
Patch Set: 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
« vpython/wheel/wheel.go ('K') | « 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",
iannucci 2017/02/21 08:34:02 try one with empty BuildTag
dnj 2017/02/21 18:19:07 Done.
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 }
88
89 var failures = []struct {
90 v string
91 err string
92 }{
93 {"foo-bar-baz-qux-quux", "missing .whl suffix"},
94 {"foo-bar-baz-qux.whl", "unknown number of segments"},
95 }
96
97 Convey(`Testing wheel name parsing`, t, func() {
98 for _, tc := range successes {
99 Convey(fmt.Sprintf(`Success: %s`, tc.v), func() {
100 wn, err := ParseName(tc.v)
101 So(err, ShouldBeNil)
102 So(wn, ShouldResemble, tc.exp)
iannucci 2017/02/21 08:34:02 do a round-trip here
dnj 2017/02/21 18:19:07 Done.
103 })
104 }
105
106 for _, tc := range failures {
107 Convey(fmt.Sprintf(`Failure: %s`, tc.v), func() {
108 _, err := ParseName(tc.v)
109 So(err, ShouldErrLike, tc.err)
110 })
111 }
112 })
113 }
114
115 func TestGlobFrom(t *testing.T) {
116 t.Parallel()
117
118 Convey(`Testing GlobFrom`, t, testfs.MustWithTempDir("TestGlobFrom", fun c(tdir string) {
119 mustBuild := func(layout map[string]string) {
120 if err := testfs.Build(tdir, layout); err != nil {
121 panic(err)
122 }
123 }
124
125 mustBuild(map[string]string{
126 "junk.bin": "",
127 "junk": "",
128 wheelMarkupSafe.String(): "",
129 wheelSimpleJSON.String(): "",
130 wheelCryptography.String(): testfs.BuildDir, // Director ies should be ignored.
131 })
132
133 Convey(`With no malformed wheels, picks up wheel names.`, func() {
134 wheels, err := GlobFrom(tdir)
135 So(err, ShouldBeNil)
136 So(wheels, ShouldResemble, []Name{wheelMarkupSafe, wheel SimpleJSON})
137 })
138
139 Convey(`With a malformed wheel name, fails.`, func() {
140 mustBuild(map[string]string{
141 "malformed-thing.whl": "",
142 })
143
144 _, err := GlobFrom(tdir)
145 So(err, ShouldErrLike, "failed to parse wheel")
146 })
147 }))
148 }
149
150 func TestWriteRequirementsFile(t *testing.T) {
151 t.Parallel()
152
153 Convey(`Can write a requirements file.`, t,
154 testfs.MustWithTempDir("TestWriteRequirementsFile", func(tdir st ring) {
155 similarSimpleJSON := wheelSimpleJSON
156 similarSimpleJSON.ABITag = "some_other_abi"
157
158 req := filepath.Join(tdir, "requirements.txt")
159 err := WriteRequirementsFile(req, []Name{
160 wheelMarkupSafe,
161 wheelSimpleJSON,
162 similarSimpleJSON,
163 wheelCryptography})
164 So(err, ShouldBeNil)
165
166 content, err := ioutil.ReadFile(req)
167 So(err, ShouldBeNil)
168 So(content, ShouldResemble, []byte(""+
169 "MarkupSafe==0.23\n"+
170 "simplejson==3.6.5\n"+
171 "cryptography==1.4\n"))
172 }))
173 }
OLDNEW
« vpython/wheel/wheel.go ('K') | « vpython/wheel/wheel.go ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698