-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Instead of passing in a granular list of allowed versions, just have two separate methods for target versions versus sources versions, since that's how it's used anyway. For simplicity in the PythonVersion class, don't intercept the IllegalArgumentException or allow the argument to be null. That can be the caller's responsibility. Also do automated formatting fixes required by presubmit. Work toward #6583. RELNOTES: None PiperOrigin-RevId: 223533178
- Loading branch information
Showing
5 changed files
with
160 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
src/test/java/com/google/devtools/build/lib/rules/python/PythonVersionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// Copyright 2018 The Bazel Authors. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package com.google.devtools.build.lib.rules.python; | ||
|
||
import static com.google.common.truth.Truth.assertThat; | ||
import static com.google.devtools.build.lib.testutil.MoreAsserts.assertThrows; | ||
|
||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.junit.runners.JUnit4; | ||
|
||
/** Tests for {@link PythonVersion}. */ | ||
@RunWith(JUnit4.class) | ||
public class PythonVersionTest { | ||
|
||
@Test | ||
public void parseTargetValue() { | ||
assertThat(PythonVersion.parseTargetValue("PY2")).isEqualTo(PythonVersion.PY2); | ||
|
||
IllegalArgumentException expected = | ||
assertThrows( | ||
IllegalArgumentException.class, () -> PythonVersion.parseTargetValue("PY2AND3")); | ||
assertThat(expected).hasMessageThat().contains("not a valid Python major version"); | ||
|
||
expected = | ||
assertThrows( | ||
IllegalArgumentException.class, | ||
() -> PythonVersion.parseTargetValue("not an enum value")); | ||
assertThat(expected).hasMessageThat().contains("not a valid Python major version"); | ||
|
||
expected = | ||
assertThrows(IllegalArgumentException.class, () -> PythonVersion.parseTargetValue("py2")); | ||
assertThat(expected).hasMessageThat().contains("not a valid Python major version"); | ||
} | ||
|
||
@Test | ||
public void parseSrcsValue() { | ||
assertThat(PythonVersion.parseSrcsValue("PY2")).isEqualTo(PythonVersion.PY2); | ||
|
||
assertThat(PythonVersion.parseSrcsValue("PY2AND3")).isEqualTo(PythonVersion.PY2AND3); | ||
|
||
IllegalArgumentException expected = | ||
assertThrows( | ||
IllegalArgumentException.class, | ||
() -> PythonVersion.parseSrcsValue("not an enum value")); | ||
assertThat(expected).hasMessageThat().contains("No enum constant"); | ||
|
||
expected = | ||
assertThrows(IllegalArgumentException.class, () -> PythonVersion.parseSrcsValue("py2")); | ||
assertThat(expected).hasMessageThat().contains("No enum constant"); | ||
} | ||
} |