| OLD | NEW |
| 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 python | 5 package python |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "fmt" | 8 "fmt" |
| 9 "os" | 9 "os" |
| 10 "os/exec" | 10 "os/exec" |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 if err != nil { | 140 if err != nil { |
| 141 t.Fatalf("failed to get executable: %s", err) | 141 t.Fatalf("failed to get executable: %s", err) |
| 142 } | 142 } |
| 143 versionString := "" | 143 versionString := "" |
| 144 | 144 |
| 145 versionSuccesses := []struct { | 145 versionSuccesses := []struct { |
| 146 output string | 146 output string |
| 147 vers Version | 147 vers Version |
| 148 }{ | 148 }{ |
| 149 {"Python 2.7.1\n", Version{2, 7, 1}}, | 149 {"Python 2.7.1\n", Version{2, 7, 1}}, |
| 150 {"Python 2.7.1+local string", Version{2, 7, 1}}, |
| 150 {"Python 3", Version{3, 0, 0}}, | 151 {"Python 3", Version{3, 0, 0}}, |
| 152 {"Python 3.1.2.3.4", Version{3, 1, 2}}, |
| 151 } | 153 } |
| 152 | 154 |
| 153 versionFailures := []struct { | 155 versionFailures := []struct { |
| 154 output string | 156 output string |
| 155 err string | 157 err string |
| 156 }{ | 158 }{ |
| 157 {"", "unknown version output"}, | 159 {"", "unknown version output"}, |
| 158 {"Python2.7.11\n", "unknown version output"}, | 160 {"Python2.7.11\n", "unknown version output"}, |
| 159 {"Python", "unknown version output"}, | 161 {"Python", "unknown version output"}, |
| 160 » » {"Python 2.7.11 foo bar junk", "invalid number value"}, | 162 » » {"Python 2.7.11 foo bar junk", "non-canonical Python version str
ing"}, |
| 161 » » {"Python 3.1.2.3.4", "failed to parse version"}, | |
| 162 } | 163 } |
| 163 | 164 |
| 164 Convey(`Testing Interpreter.GetVersion`, t, func() { | 165 Convey(`Testing Interpreter.GetVersion`, t, func() { |
| 165 c := context.Background() | 166 c := context.Background() |
| 166 | 167 |
| 167 i := Interpreter{ | 168 i := Interpreter{ |
| 168 Python: self, | 169 Python: self, |
| 169 | 170 |
| 170 testCommandHook: func(cmd *exec.Cmd) { | 171 testCommandHook: func(cmd *exec.Cmd) { |
| 171 var env environ.Env | 172 var env environ.Env |
| (...skipping 15 matching lines...) Expand all Loading... |
| 187 for _, tc := range versionFailures { | 188 for _, tc := range versionFailures { |
| 188 Convey(fmt.Sprintf(`Will fail to parse %q (%s)`, tc.outp
ut, tc.err), func() { | 189 Convey(fmt.Sprintf(`Will fail to parse %q (%s)`, tc.outp
ut, tc.err), func() { |
| 189 versionString = tc.output | 190 versionString = tc.output |
| 190 | 191 |
| 191 _, err := i.GetVersion(c) | 192 _, err := i.GetVersion(c) |
| 192 So(err, ShouldErrLike, tc.err) | 193 So(err, ShouldErrLike, tc.err) |
| 193 }) | 194 }) |
| 194 } | 195 } |
| 195 }) | 196 }) |
| 196 } | 197 } |
| OLD | NEW |