go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/vpython/wheels/pep425_test.go (about)

     1  // Copyright 2022 The LUCI Authors.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //      http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package wheels
    16  
    17  import (
    18  	"fmt"
    19  	"strings"
    20  	"testing"
    21  
    22  	"go.chromium.org/luci/cipd/client/cipd/template"
    23  
    24  	"go.chromium.org/luci/vpython/api/vpython"
    25  
    26  	. "github.com/smartystreets/goconvey/convey"
    27  	. "go.chromium.org/luci/common/testing/assertions"
    28  )
    29  
    30  func TestPEP425TagSelector(t *testing.T) {
    31  	t.Parallel()
    32  
    33  	testCases := []struct {
    34  		tags     []*vpython.PEP425Tag
    35  		template map[string]string
    36  	}{
    37  		{
    38  			[]*vpython.PEP425Tag{
    39  				{Python: "py2", Abi: "none", Platform: "any"},
    40  				{Python: "py27", Abi: "none", Platform: "any"},
    41  				{Python: "cp27", Abi: "cp27mu", Platform: "linux_x86_64"},
    42  				{Python: "cp27", Abi: "cp27mu", Platform: "manylinux1_x86_64"},
    43  				{Python: "cp27", Abi: "none", Platform: "manylinux1_x86_64"},
    44  			},
    45  			map[string]string{
    46  				"platform":         "linux-amd64",
    47  				"py_tag":           "cp27-cp27mu-manylinux1_x86_64",
    48  				"py_python":        "cp27",
    49  				"py_abi":           "cp27mu",
    50  				"py_platform":      "manylinux1_x86_64",
    51  				"vpython_platform": "linux-amd64_cp27_cp27mu",
    52  			},
    53  		},
    54  
    55  		{
    56  			[]*vpython.PEP425Tag{
    57  				{Python: "cp27", Abi: "cp27m", Platform: "macosx_10_12_x86_64"},
    58  				{Python: "cp27", Abi: "cp27m", Platform: "macosx_10_12_fat64"},
    59  				{Python: "cp27", Abi: "cp27m", Platform: "macosx_10_12_fat32"},
    60  				{Python: "cp27", Abi: "cp27m", Platform: "macosx_10_12_intel"},
    61  				{Python: "cp27", Abi: "cp27m", Platform: "macosx_10_10_intel"},
    62  				{Python: "cp27", Abi: "cp27m", Platform: "macosx_10_9_fat64"},
    63  				{Python: "cp27", Abi: "cp27m", Platform: "macosx_10_9_fat32"},
    64  				{Python: "cp27", Abi: "cp27m", Platform: "macosx_10_9_universal"},
    65  				{Python: "cp27", Abi: "cp27m", Platform: "macosx_10_8_fat32"},
    66  				{Python: "cp27", Abi: "cp27m", Platform: "macosx_10_8_universal"},
    67  				{Python: "cp27", Abi: "cp27m", Platform: "macosx_10_6_intel"},
    68  				{Python: "cp27", Abi: "cp27m", Platform: "macosx_10_6_fat64"},
    69  				{Python: "cp27", Abi: "cp27m", Platform: "macosx_10_6_fat32"},
    70  				{Python: "cp27", Abi: "cp27m", Platform: "macosx_10_6_universal"},
    71  				{Python: "cp27", Abi: "cp27m", Platform: "macosx_10_5_universal"},
    72  				{Python: "cp27", Abi: "cp27m", Platform: "macosx_10_4_intel"},
    73  				{Python: "cp27", Abi: "cp27m", Platform: "macosx_10_4_fat32"},
    74  				{Python: "cp27", Abi: "cp27m", Platform: "macosx_10_1_universal"},
    75  				{Python: "cp27", Abi: "cp27m", Platform: "macosx_10_0_fat32"},
    76  				{Python: "cp27", Abi: "cp27m", Platform: "macosx_10_0_universal"},
    77  				{Python: "cp27", Abi: "none", Platform: "macosx_10_12_x86_64"},
    78  				{Python: "cp27", Abi: "none", Platform: "macosx_10_12_intel"},
    79  				{Python: "cp27", Abi: "none", Platform: "macosx_10_12_fat64"},
    80  				{Python: "cp27", Abi: "none", Platform: "macosx_10_9_universal"},
    81  				{Python: "cp27", Abi: "none", Platform: "macosx_10_8_x86_64"},
    82  				{Python: "cp27", Abi: "none", Platform: "macosx_10_8_intel"},
    83  				{Python: "cp27", Abi: "none", Platform: "macosx_10_7_intel"},
    84  				{Python: "cp27", Abi: "none", Platform: "macosx_10_7_fat64"},
    85  				{Python: "cp27", Abi: "none", Platform: "macosx_10_7_fat32"},
    86  				{Python: "cp27", Abi: "none", Platform: "macosx_10_6_universal"},
    87  				{Python: "cp27", Abi: "none", Platform: "macosx_10_5_x86_64"},
    88  				{Python: "cp27", Abi: "none", Platform: "macosx_10_5_intel"},
    89  				{Python: "cp27", Abi: "none", Platform: "macosx_10_3_fat32"},
    90  				{Python: "cp27", Abi: "none", Platform: "macosx_10_3_universal"},
    91  				{Python: "cp27", Abi: "none", Platform: "macosx_10_2_fat32"},
    92  				{Python: "py2", Abi: "none", Platform: "macosx_10_4_intel"},
    93  				{Python: "cp27", Abi: "none", Platform: "any"},
    94  				{Python: "cp27", Abi: "cp27m", Platform: "macosx_11_0_intel"},
    95  				{Python: "py2", Abi: "none", Platform: "macosx_10_3_intel"},
    96  			},
    97  			map[string]string{
    98  				"platform":         "mac-amd64",
    99  				"py_tag":           "cp27-cp27m-macosx_10_4_intel",
   100  				"py_python":        "cp27",
   101  				"py_abi":           "cp27m",
   102  				"py_platform":      "macosx_10_4_intel",
   103  				"vpython_platform": "mac-amd64_cp27_cp27m",
   104  			},
   105  		},
   106  
   107  		{
   108  			[]*vpython.PEP425Tag{
   109  				{Python: "py27", Abi: "none", Platform: "any"},
   110  				{Python: "py27", Abi: "none", Platform: "linux_i686"},
   111  			},
   112  			map[string]string{
   113  				"platform":         "linux-386",
   114  				"py_tag":           "py27-none-linux_i686",
   115  				"py_python":        "py27",
   116  				"py_abi":           "none",
   117  				"py_platform":      "linux_i686",
   118  				"vpython_platform": "linux-386_py27_none",
   119  			},
   120  		},
   121  
   122  		{
   123  			[]*vpython.PEP425Tag{
   124  				{Python: "py27", Abi: "none", Platform: "any"},
   125  				{Python: "py27", Abi: "none", Platform: "linux_x86_64"},
   126  			},
   127  			map[string]string{
   128  				"platform":         "linux-amd64",
   129  				"py_tag":           "py27-none-linux_x86_64",
   130  				"py_python":        "py27",
   131  				"py_abi":           "none",
   132  				"py_platform":      "linux_x86_64",
   133  				"vpython_platform": "linux-amd64_py27_none",
   134  			},
   135  		},
   136  
   137  		{
   138  			// Tags taken from actual output running vpython3 on Linux x64.
   139  			[]*vpython.PEP425Tag{
   140  				{Python: "cp3", Abi: "none", Platform: "any"},
   141  				{Python: "cp32", Abi: "abi3", Platform: "linux_x86_64"},
   142  				{Python: "cp32", Abi: "abi3", Platform: "manylinux1_x86_64"},
   143  				{Python: "cp33", Abi: "abi3", Platform: "linux_x86_64"},
   144  				{Python: "cp33", Abi: "abi3", Platform: "manylinux1_x86_64"},
   145  				{Python: "cp34", Abi: "abi3", Platform: "linux_x86_64"},
   146  				{Python: "cp34", Abi: "abi3", Platform: "manylinux1_x86_64"},
   147  				{Python: "cp35", Abi: "abi3", Platform: "linux_x86_64"},
   148  				{Python: "cp35", Abi: "abi3", Platform: "manylinux1_x86_64"},
   149  				{Python: "cp36", Abi: "abi3", Platform: "linux_x86_64"},
   150  				{Python: "cp36", Abi: "abi3", Platform: "manylinux1_x86_64"},
   151  				{Python: "cp37", Abi: "abi3", Platform: "linux_x86_64"},
   152  				{Python: "cp37", Abi: "abi3", Platform: "manylinux1_x86_64"},
   153  				{Python: "cp38", Abi: "abi3", Platform: "linux_x86_64"},
   154  				{Python: "cp38", Abi: "abi3", Platform: "manylinux1_x86_64"},
   155  				{Python: "cp38", Abi: "cp38", Platform: "linux_x86_64"},
   156  				{Python: "cp38", Abi: "cp38", Platform: "manylinux1_x86_64"},
   157  				{Python: "cp38", Abi: "none", Platform: "any"},
   158  				{Python: "cp38", Abi: "none", Platform: "linux_x86_64"},
   159  				{Python: "cp38", Abi: "none", Platform: "manylinux1_x86_64"},
   160  				{Python: "py3", Abi: "none", Platform: "any"},
   161  				{Python: "py3", Abi: "none", Platform: "linux_x86_64"},
   162  				{Python: "py3", Abi: "none", Platform: "manylinux1_x86_64"},
   163  				{Python: "py30", Abi: "none", Platform: "any"},
   164  				{Python: "py31", Abi: "none", Platform: "any"},
   165  				{Python: "py32", Abi: "none", Platform: "any"},
   166  				{Python: "py33", Abi: "none", Platform: "any"},
   167  				{Python: "py34", Abi: "none", Platform: "any"},
   168  				{Python: "py35", Abi: "none", Platform: "any"},
   169  				{Python: "py36", Abi: "none", Platform: "any"},
   170  				{Python: "py37", Abi: "none", Platform: "any"},
   171  				{Python: "py38", Abi: "none", Platform: "any"},
   172  			},
   173  			map[string]string{
   174  				"platform":         "linux-amd64",
   175  				"py_tag":           "cp38-cp38-manylinux1_x86_64",
   176  				"py_python":        "cp38",
   177  				"py_abi":           "cp38",
   178  				"py_platform":      "manylinux1_x86_64",
   179  				"vpython_platform": "linux-amd64_cp38_cp38",
   180  			},
   181  		},
   182  
   183  		{
   184  			[]*vpython.PEP425Tag{
   185  				{Python: "cp3", Abi: "none", Platform: "any"},
   186  				{Python: "cp32", Abi: "abi3", Platform: "linux_x86_64"},
   187  				{Python: "cp32", Abi: "abi3", Platform: "manylinux1_x86_64"},
   188  				{Python: "cp33", Abi: "abi3", Platform: "linux_x86_64"},
   189  				{Python: "cp33", Abi: "abi3", Platform: "manylinux1_x86_64"},
   190  				{Python: "cp34", Abi: "abi3", Platform: "linux_x86_64"},
   191  				{Python: "cp34", Abi: "abi3", Platform: "manylinux1_x86_64"},
   192  				{Python: "cp35", Abi: "abi3", Platform: "linux_x86_64"},
   193  				{Python: "cp35", Abi: "abi3", Platform: "manylinux1_x86_64"},
   194  				{Python: "cp36", Abi: "abi3", Platform: "linux_x86_64"},
   195  				{Python: "cp36", Abi: "abi3", Platform: "manylinux1_x86_64"},
   196  				{Python: "cp37", Abi: "abi3", Platform: "linux_x86_64"},
   197  				{Python: "cp37", Abi: "abi3", Platform: "manylinux1_x86_64"},
   198  				{Python: "cp38", Abi: "abi3", Platform: "linux_x86_64"},
   199  				{Python: "cp38", Abi: "abi3", Platform: "manylinux1_x86_64"},
   200  				{Python: "cp38", Abi: "abi3", Platform: "linux_x86_64"},
   201  				{Python: "cp38", Abi: "abi3", Platform: "manylinux1_x86_64"},
   202  				{Python: "cp39", Abi: "cp39", Platform: "linux_x86_64"},
   203  				{Python: "cp39", Abi: "cp39", Platform: "manylinux1_x86_64"},
   204  				{Python: "cp39", Abi: "none", Platform: "any"},
   205  				{Python: "cp39", Abi: "none", Platform: "linux_x86_64"},
   206  				{Python: "cp39", Abi: "none", Platform: "manylinux1_x86_64"},
   207  				{Python: "py3", Abi: "none", Platform: "any"},
   208  				{Python: "py3", Abi: "none", Platform: "linux_x86_64"},
   209  				{Python: "py3", Abi: "none", Platform: "manylinux1_x86_64"},
   210  				{Python: "py30", Abi: "none", Platform: "any"},
   211  				{Python: "py31", Abi: "none", Platform: "any"},
   212  				{Python: "py32", Abi: "none", Platform: "any"},
   213  				{Python: "py33", Abi: "none", Platform: "any"},
   214  				{Python: "py34", Abi: "none", Platform: "any"},
   215  				{Python: "py35", Abi: "none", Platform: "any"},
   216  				{Python: "py36", Abi: "none", Platform: "any"},
   217  				{Python: "py37", Abi: "none", Platform: "any"},
   218  				{Python: "py38", Abi: "none", Platform: "any"},
   219  			},
   220  			map[string]string{
   221  				"platform":         "linux-amd64",
   222  				"py_tag":           "cp39-cp39-manylinux1_x86_64",
   223  				"py_python":        "cp39",
   224  				"py_abi":           "cp39",
   225  				"py_platform":      "manylinux1_x86_64",
   226  				"vpython_platform": "linux-amd64_cp39_cp39",
   227  			},
   228  		},
   229  
   230  		{
   231  			[]*vpython.PEP425Tag{
   232  				{Python: "cp38", Abi: "cp38", Platform: "win_amd64"},
   233  				{Python: "cp38", Abi: "none", Platform: "win_amd64"},
   234  				{Python: "py3", Abi: "none", Platform: "win_amd64"},
   235  				{Python: "cp38", Abi: "none", Platform: "any"},
   236  				{Python: "cp3", Abi: "none", Platform: "any"},
   237  				{Python: "py38", Abi: "none", Platform: "any"},
   238  				{Python: "py3", Abi: "none", Platform: "any"},
   239  				{Python: "py37", Abi: "none", Platform: "any"},
   240  				{Python: "py36", Abi: "none", Platform: "any"},
   241  				{Python: "py35", Abi: "none", Platform: "any"},
   242  				{Python: "py34", Abi: "none", Platform: "any"},
   243  				{Python: "py33", Abi: "none", Platform: "any"},
   244  				{Python: "py32", Abi: "none", Platform: "any"},
   245  				{Python: "py31", Abi: "none", Platform: "any"},
   246  				{Python: "py30", Abi: "none", Platform: "any"},
   247  			},
   248  			map[string]string{
   249  				"platform":         "windows-amd64",
   250  				"py_tag":           "cp38-cp38-win_amd64",
   251  				"py_python":        "cp38",
   252  				"py_abi":           "cp38",
   253  				"py_platform":      "win_amd64",
   254  				"vpython_platform": "windows-amd64_cp38_cp38",
   255  			},
   256  		},
   257  
   258  		{
   259  			[]*vpython.PEP425Tag{
   260  				{Python: "cp38", Abi: "abi3", Platform: "macosx_10_12_x86_64"},
   261  				{Python: "cp38", Abi: "abi3", Platform: "macosx_10_12_intel"},
   262  				{Python: "cp38", Abi: "abi3", Platform: "macosx_10_12_fat64"},
   263  				{Python: "cp38", Abi: "abi3", Platform: "macosx_10_12_fat32"},
   264  				{Python: "cp38", Abi: "abi3", Platform: "macosx_10_12_arm64"},
   265  				{Python: "cp38", Abi: "abi3", Platform: "macosx_10_12_universal"},
   266  				{Python: "cp38", Abi: "abi3", Platform: "macosx_10_11_arm64"},
   267  			},
   268  			map[string]string{
   269  				"platform":         "mac-arm64",
   270  				"py_tag":           "cp38-abi3-macosx_10_11_arm64",
   271  				"py_python":        "cp38",
   272  				"py_abi":           "abi3",
   273  				"py_platform":      "macosx_10_11_arm64",
   274  				"vpython_platform": "mac-arm64_cp38_abi3",
   275  			},
   276  		},
   277  	}
   278  
   279  	Convey(`Testing PEP425 tag selection`, t, func() {
   280  		for i, tc := range testCases {
   281  			tagsStr := make([]string, len(tc.tags))
   282  			for i, tag := range tc.tags {
   283  				tagsStr[i] = tag.TagString()
   284  			}
   285  			t.Logf("Test case #%d, using tags: %v", i, tagsStr)
   286  
   287  			tagsList := strings.Join(tagsStr, ", ")
   288  			Convey(fmt.Sprintf(`Generates template for [%s]`, tagsList), func() {
   289  				tag := pep425TagSelector(tc.tags)
   290  
   291  				expander := make(template.Expander)
   292  				err := addPEP425CIPDTemplateForTag(expander, tag)
   293  				So(err, ShouldBeNil)
   294  				So(map[string]string(expander), ShouldResemble, tc.template)
   295  			})
   296  		}
   297  
   298  		Convey(`Returns an error when no tag is selected.`, func() {
   299  			tag := pep425TagSelector(nil)
   300  			So(tag, ShouldBeNil)
   301  
   302  			expander := make(template.Expander)
   303  			err := addPEP425CIPDTemplateForTag(expander, tag)
   304  			So(err, ShouldErrLike, "no PEP425 tag")
   305  		})
   306  
   307  		Convey(`Returns an error when an unknown platform is selected.`, func() {
   308  			tag := pep425TagSelector([]*vpython.PEP425Tag{
   309  				{Python: "py27", Abi: "none", Platform: "any"},
   310  				{Python: "py27", Abi: "foo", Platform: "bar"},
   311  			})
   312  			So(tag, ShouldResembleProto, &vpython.PEP425Tag{Python: "py27", Abi: "foo", Platform: "bar"})
   313  
   314  			expander := make(template.Expander)
   315  			err := addPEP425CIPDTemplateForTag(expander, tag)
   316  			So(err, ShouldErrLike, "failed to infer CIPD platform for tag")
   317  		})
   318  	})
   319  }