Skip to content

Commit 873912d

Browse files
fredrectensorflower-gardener
authored andcommitted
Add a smoke test that installs then tries to import TFMOT
Prevents issues such as #839 to occur again. PiperOrigin-RevId: 419361648
1 parent 12dc84d commit 873912d

File tree

3 files changed

+60
-4
lines changed

3 files changed

+60
-4
lines changed

ci/kokoro/gcp_ubuntu/build.sh

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#!/bin/bash
2-
32
# Copyright 2020 Google LLC
43
#
54
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -81,5 +80,8 @@ docker run \
8180
# On exit: collect the test logs and stop the container.
8281
trap cleanup EXIT
8382

84-
# Run the tests inside the container,
85-
docker exec tfmot "${GIT_REPO_DIR}/ci/kokoro/build.sh"
83+
# Run the unit tests inside the container.
84+
docker exec tfmot "${GIT_REPO_DIR}/ci/kokoro/run_bazel_unittests.sh"
85+
86+
# Run the install/import test inside the container.
87+
docker exec tfmot "${GIT_REPO_DIR}/ci/kokoro/run_install_import_test.sh"

ci/kokoro/build.sh renamed to ci/kokoro/run_bazel_unittests.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
22

3-
# Copyright 2020 Google LLC
3+
# Copyright 2021 Google LLC
44
#
55
# Licensed under the Apache License, Version 2.0 (the "License");
66
# you may not use this file except in compliance with the License.
@@ -14,6 +14,10 @@
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
1616

17+
#
18+
# Runs the unit tests with Bazel.
19+
#
20+
1721
# Make Bash more strict, for easier debugging.
1822
set -e # Exit on the first error.
1923
set -u # Treat unset variables as error.

ci/kokoro/run_install_import_test.sh

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#!/bin/bash
2+
3+
# Copyright 2021 Google LLC
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# https://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
#
18+
# A smoke test that installs TFMOT with `setup.py install` and then tries to
19+
# import it.
20+
#
21+
22+
# Make Bash more strict, for easier debugging.
23+
set -e # Exit on the first error.
24+
set -u # Treat unset variables as error.
25+
set -o pipefail # Treat the failure of a command in a pipeline as error.
26+
27+
# Display commands being run.
28+
# WARNING: please only enable 'set -x' if necessary for debugging, and be very
29+
# careful if you handle credentials (e.g. from Keystore) with 'set -x':
30+
# statements like "export VAR=$(cat /tmp/keystore/credentials)" will result in
31+
# the credentials being printed in build logs.
32+
# Additionally, recursive invocation with credentials as command-line
33+
# parameters, will print the full command, with credentials, in the build logs.
34+
# set -x
35+
36+
37+
# Create an isolated Python environment.
38+
mkdir venv
39+
virtualenv ./venv
40+
source ./venv/bin/activate
41+
42+
# Install Tensorflow, then TFMOT from source.
43+
pip install tensorflow
44+
pip install --requirement "requirements.txt"
45+
python setup.py install
46+
47+
# Go to another directory and try to import TFMOT.
48+
mkdir /tmp/my_project
49+
pushd /tmp/my_project
50+
python -c "import tensorflow_model_optimization"

0 commit comments

Comments
 (0)