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

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

Issue 2927573002: [vpython] Fix PEP425 naming. (Closed)
Patch Set: rebase and update Created 3 years, 6 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/match.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
1 // Copyright 2017 The LUCI Authors. All rights reserved. 1 // Copyright 2017 The LUCI Authors. All rights reserved.
2 // Use of this source code is governed under the Apache License, Version 2.0 2 // Use of this source code is governed under the Apache License, Version 2.0
3 // that can be found in the LICENSE file. 3 // that can be found in the LICENSE file.
4 4
5 package spec 5 package spec
6 6
7 import ( 7 import (
8 "fmt" 8 "fmt"
9 "strings" 9 "strings"
10 "testing" 10 "testing"
11 11
12 "github.com/luci/luci-go/vpython/api/vpython" 12 "github.com/luci/luci-go/vpython/api/vpython"
13 13
14 . "github.com/smartystreets/goconvey/convey" 14 . "github.com/smartystreets/goconvey/convey"
15 ) 15 )
16 16
17 func mkTag(version, abi, arch string) *vpython.Pep425Tag { 17 func mkTag(python, abi, platform string) *vpython.PEP425Tag {
18 » return &vpython.Pep425Tag{ 18 » return &vpython.PEP425Tag{
19 » » Version: version, 19 » » Python: python,
20 » » Abi: abi, 20 » » Abi: abi,
21 » » Arch: arch, 21 » » Platform: platform,
22 } 22 }
23 } 23 }
24 24
25 func tagString(tags []*vpython.Pep425Tag) string { 25 func tagString(tags []*vpython.PEP425Tag) string {
26 parts := make([]string, len(tags)) 26 parts := make([]string, len(tags))
27 for i, tag := range tags { 27 for i, tag := range tags {
28 parts[i] = tag.TagString() 28 parts[i] = tag.TagString()
29 } 29 }
30 return strings.Join(parts, ", ") 30 return strings.Join(parts, ", ")
31 } 31 }
32 32
33 func TestPEP425Matches(t *testing.T) { 33 func TestPEP425Matches(t *testing.T) {
34 t.Parallel() 34 t.Parallel()
35 35
36 testCases := []struct { 36 testCases := []struct {
37 » » tags []*vpython.Pep425Tag 37 » » tags []*vpython.PEP425Tag
38 » » matches []*vpython.Pep425Tag 38 » » matches []*vpython.PEP425Tag
39 » » notMatches []*vpython.Pep425Tag 39 » » notMatches []*vpython.PEP425Tag
40 }{ 40 }{
41 { 41 {
42 tags: nil, 42 tags: nil,
43 » » » notMatches: []*vpython.Pep425Tag{ 43 » » » notMatches: []*vpython.PEP425Tag{
44 mkTag("", "", ""), 44 mkTag("", "", ""),
45 mkTag("cp27", "cp27mu", "manylinux1_x86_64"), 45 mkTag("cp27", "cp27mu", "manylinux1_x86_64"),
46 }, 46 },
47 }, 47 },
48 { 48 {
49 » » » tags: []*vpython.Pep425Tag{ 49 » » » tags: []*vpython.PEP425Tag{
50 mkTag("cp27", "cp27mu", "manylinux1_x86_64"), 50 mkTag("cp27", "cp27mu", "manylinux1_x86_64"),
51 mkTag("py2", "cp27m", "macosx_10_9_universal"), 51 mkTag("py2", "cp27m", "macosx_10_9_universal"),
52 }, 52 },
53 » » » matches: []*vpython.Pep425Tag{ 53 » » » matches: []*vpython.PEP425Tag{
54 mkTag("cp27", "", ""), 54 mkTag("cp27", "", ""),
55 mkTag("", "cp27mu", ""), 55 mkTag("", "cp27mu", ""),
56 mkTag("", "", "manylinux1_x86_64"), 56 mkTag("", "", "manylinux1_x86_64"),
57 mkTag("py2", "", ""), 57 mkTag("py2", "", ""),
58 mkTag("", "cp27m", ""), 58 mkTag("", "cp27m", ""),
59 mkTag("", "", "macosx_10_9_universal"), 59 mkTag("", "", "macosx_10_9_universal"),
60 mkTag("", "cp27mu", "manylinux1_x86_64"), 60 mkTag("", "cp27mu", "manylinux1_x86_64"),
61 }, 61 },
62 » » » notMatches: []*vpython.Pep425Tag{ 62 » » » notMatches: []*vpython.PEP425Tag{
63 mkTag("", "", ""), 63 mkTag("", "", ""),
64 mkTag("cp27", "cp27mu", "win_amd64"), 64 mkTag("cp27", "cp27mu", "win_amd64"),
65 mkTag("cp27", "cp27mu", "macosx_10_9_universal") , 65 mkTag("cp27", "cp27mu", "macosx_10_9_universal") ,
66 }, 66 },
67 }, 67 },
68 { 68 {
69 » » » tags: []*vpython.Pep425Tag{ 69 » » » tags: []*vpython.PEP425Tag{
70 mkTag("cp27", "cp27mu", ""), 70 mkTag("cp27", "cp27mu", ""),
71 }, 71 },
72 » » » matches: []*vpython.Pep425Tag{ 72 » » » matches: []*vpython.PEP425Tag{
73 mkTag("cp27", "cp27mu", ""), 73 mkTag("cp27", "cp27mu", ""),
74 }, 74 },
75 » » » notMatches: []*vpython.Pep425Tag{ 75 » » » notMatches: []*vpython.PEP425Tag{
76 mkTag("", "", ""), 76 mkTag("", "", ""),
77 mkTag("cp27", "cp27mu", "otherArch"), 77 mkTag("cp27", "cp27mu", "otherArch"),
78 }, 78 },
79 }, 79 },
80 } 80 }
81 81
82 Convey(`Test cases for PEP425 tag matching`, t, func() { 82 Convey(`Test cases for PEP425 tag matching`, t, func() {
83 for _, tc := range testCases { 83 for _, tc := range testCases {
84 Convey(fmt.Sprintf(`With system tags: %s`, tagString(tc. tags)), func() { 84 Convey(fmt.Sprintf(`With system tags: %s`, tagString(tc. tags)), func() {
85 for _, m := range tc.matches { 85 for _, m := range tc.matches {
86 Convey(fmt.Sprintf(`Tag matches: %s`, m. TagString()), func() { 86 Convey(fmt.Sprintf(`Tag matches: %s`, m. TagString()), func() {
87 So(PEP425Matches(m, tc.tags), Sh ouldBeTrue) 87 So(PEP425Matches(m, tc.tags), Sh ouldBeTrue)
88 }) 88 })
89 } 89 }
90 90
91 for _, m := range tc.notMatches { 91 for _, m := range tc.notMatches {
92 Convey(fmt.Sprintf(`Tag doesn't match: % s`, m.TagString()), func() { 92 Convey(fmt.Sprintf(`Tag doesn't match: % s`, m.TagString()), func() {
93 So(PEP425Matches(m, tc.tags), Sh ouldBeFalse) 93 So(PEP425Matches(m, tc.tags), Sh ouldBeFalse)
94 }) 94 })
95 } 95 }
96 }) 96 })
97 } 97 }
98 }) 98 })
99 } 99 }
100 100
101 func TestPackageMatches(t *testing.T) { 101 func TestPackageMatches(t *testing.T) {
102 t.Parallel() 102 t.Parallel()
103 103
104 » mkPkg := func(name string, tags ...*vpython.Pep425Tag) *vpython.Spec_Pac kage { 104 » mkPkg := func(name string, tags ...*vpython.PEP425Tag) *vpython.Spec_Pac kage {
105 return &vpython.Spec_Package{ 105 return &vpython.Spec_Package{
106 Name: name, 106 Name: name,
107 MatchTag: tags, 107 MatchTag: tags,
108 } 108 }
109 } 109 }
110 110
111 testCases := []struct { 111 testCases := []struct {
112 » » tags []*vpython.Pep425Tag 112 » » tags []*vpython.PEP425Tag
113 matchPkgs []*vpython.Spec_Package 113 matchPkgs []*vpython.Spec_Package
114 notMatchPkgs []*vpython.Spec_Package 114 notMatchPkgs []*vpython.Spec_Package
115 }{ 115 }{
116 { 116 {
117 tags: nil, 117 tags: nil,
118 matchPkgs: []*vpython.Spec_Package{ 118 matchPkgs: []*vpython.Spec_Package{
119 mkPkg("NoTags"), 119 mkPkg("NoTags"),
120 }, 120 },
121 notMatchPkgs: []*vpython.Spec_Package{ 121 notMatchPkgs: []*vpython.Spec_Package{
122 mkPkg("EmptyMatch", mkTag("", "", "")), 122 mkPkg("EmptyMatch", mkTag("", "", "")),
123 mkPkg("MissingMatch", mkTag("cp27", "cp27mu", "m anylinux1_x86_64")), 123 mkPkg("MissingMatch", mkTag("cp27", "cp27mu", "m anylinux1_x86_64")),
124 }, 124 },
125 }, 125 },
126 { 126 {
127 » » » tags: []*vpython.Pep425Tag{ 127 » » » tags: []*vpython.PEP425Tag{
128 mkTag("cp27", "cp27mu", "manylinux1_x86_64"), 128 mkTag("cp27", "cp27mu", "manylinux1_x86_64"),
129 mkTag("py2", "cp27m", "macosx_10_9_universal"), 129 mkTag("py2", "cp27m", "macosx_10_9_universal"),
130 }, 130 },
131 matchPkgs: []*vpython.Spec_Package{ 131 matchPkgs: []*vpython.Spec_Package{
132 mkPkg("NoTags"), 132 mkPkg("NoTags"),
133 mkPkg("OneMatchingTag", mkTag("cp27", "", "")), 133 mkPkg("OneMatchingTag", mkTag("cp27", "", "")),
134 mkPkg("MultipleMatchingTag", mkTag("cp27", "", " "), mkTag("", "cp27m", "")), 134 mkPkg("MultipleMatchingTag", mkTag("cp27", "", " "), mkTag("", "cp27m", "")),
135 }, 135 },
136 notMatchPkgs: []*vpython.Spec_Package{ 136 notMatchPkgs: []*vpython.Spec_Package{
137 mkPkg("EmptyMatch", mkTag("", "", "")), 137 mkPkg("EmptyMatch", mkTag("", "", "")),
(...skipping 13 matching lines...) Expand all
151 151
152 for _, m := range tc.notMatchPkgs { 152 for _, m := range tc.notMatchPkgs {
153 Convey(fmt.Sprintf(`Package %q doesn't m atch: %s`, m.Name, tagString(m.MatchTag)), func() { 153 Convey(fmt.Sprintf(`Package %q doesn't m atch: %s`, m.Name, tagString(m.MatchTag)), func() {
154 So(PackageMatches(m, tc.tags), S houldBeFalse) 154 So(PackageMatches(m, tc.tags), S houldBeFalse)
155 }) 155 })
156 } 156 }
157 }) 157 })
158 } 158 }
159 }) 159 })
160 } 160 }
OLDNEW
« no previous file with comments | « vpython/spec/match.go ('k') | vpython/spec/spec.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698