Skip to content

Commit 8fb71b3

Browse files
authored
Improve pre-merge tests and code formatting (#212)
- Add `set -e` to the test script. This fixes an issue where PR checks have been passing even when tests fail because the test script overall exits with code 0. - Add test script modes for env setup, lint fix, and running all tests. Before, "Python test" mode also set up the environment and ran formatting tests. - Add isort alongside yapf. This follows precedent in the website repo. - Add datacommons_client dir to the paths checked by yapf (and isort). - Rename run_tests to run_test for consistency with other repos.
1 parent 91bfe23 commit 8fb71b3

36 files changed

+1950
-1788
lines changed

cloudbuild.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ steps:
44
entrypoint: /bin/sh
55
args:
66
- -c
7-
- "./run_tests.sh -p"
7+
- "./run_test.sh -s -a"

datacommons/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
# isort: skip_file
16+
1517
################################## IMPORTANT #################################
1618
# All user-facing functions in this package must be symlinked to the #
1719
# datacommons_pandas pkg. This is so that users do not need to import both #
@@ -30,4 +32,4 @@
3032
from datacommons.stat_vars import get_stat_value, get_stat_series, get_stat_all
3133

3234
from datacommons.key import set_api_key
33-
from datacommons.node import properties, property_values, triples
35+
from datacommons.node import properties, property_values, triples

datacommons/examples/stat_vars.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@
1717
from __future__ import division
1818
from __future__ import print_function
1919

20-
import datacommons as dc
2120
import pprint
2221

22+
import datacommons as dc
23+
2324

2425
def main():
2526
param_sets = [

datacommons/requests.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@
1414
""" Send http requests to Data Commons REST API endpoints.
1515
"""
1616

17-
import requests
1817
from typing import Dict
1918

19+
import requests
20+
2021
import datacommons.key as key
2122

2223
# REST API endpoint root

datacommons/setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
# limitations under the License.
1414
"""Build and distribute the datacommons package to PyPI."""
1515
import os
16+
1617
from setuptools import setup
1718

1819
dir_path = os.path.dirname(os.path.realpath(__file__))

datacommons/stat_vars.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
from __future__ import print_function
2222

2323
import collections
24+
2425
import six
2526

2627
import datacommons.utils as utils

datacommons/test/core_test.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,13 @@
2525
except ImportError:
2626
from mock import patch
2727

28+
import json
29+
import unittest
30+
2831
import six.moves.urllib as urllib
2932

3033
import datacommons as dc
3134
import datacommons.utils as utils
32-
import json
33-
import unittest
3435

3536

3637
def request_mock(*args, **kwargs):

datacommons/test/places_test.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,14 @@
2525
except ImportError:
2626
from mock import patch
2727

28-
import datacommons as dc
29-
import datacommons.utils as utils
3028
import json
3129
import unittest
30+
3231
import six.moves.urllib as urllib
3332

33+
import datacommons as dc
34+
import datacommons.utils as utils
35+
3436

3537
def request_mock(*args, **kwargs):
3638
""" A mock urlopen requests sent in the requests package. """

datacommons/test/stat_vars_test.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,15 @@
2525
except ImportError:
2626
from mock import patch
2727

28-
import datacommons as dc
29-
import datacommons.utils as utils
30-
import math
3128
import json
29+
import math
3230
import unittest
31+
3332
import six.moves.urllib as urllib
3433

34+
import datacommons as dc
35+
import datacommons.utils as utils
36+
3537
# Reusable parts of REST API /stat/all response.
3638
CA_COUNT_PERSON = {
3739
"isDcAggregate":

datacommons/utils.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@
2020
from __future__ import division
2121
from __future__ import print_function
2222

23-
from collections import defaultdict
24-
2523
import base64
24+
from collections import defaultdict
2625
import json
2726
import os
27+
import zlib
28+
2829
import six.moves.urllib.error
2930
import six.moves.urllib.request
30-
import zlib
3131

3232
# --------------------------------- CONSTANTS ---------------------------------
3333

0 commit comments

Comments
 (0)