8000 chore: use templated 'noxfile.py' (#355) · googleapis/python-bigtable@2ee65b7 · GitHub
[go: up one dir, main page]

Skip to content

Commit 2ee65b7

Browse files
authored
chore: use templated 'noxfile.py' (#355)
Extracted from PR #325. Closes #324.
1 parent aa5b606 commit 2ee65b7

File tree

3 files changed

+84
-28
lines changed

3 files changed

+84
-28
lines changed

noxfile.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@
4545
"docs",
4646
]
4747

48+
# Error if a python version is missing
49+
nox.options.error_on_missing_interpreters = True
50+
4851

4952
@nox.session(python=DEFAULT_PYTHON_VERSION)
5053
def lint(session):
@@ -62,10 +65,7 @@ def lint(session):
6265

6366
@nox.session(python=DEFAULT_PYTHON_VERSION)
6467
def blacken(session):
65-
"""Run black.
66-
67-
Format code to uniform standard.
68-
"""
68+
"""Run black. Format code to uniform standard."""
6969
session.install(BLACK_VERSION)
7070
session.run(
7171
"black", *BLACK_PATHS,
@@ -81,6 +81,7 @@ def lint_setup_py(session):
8181

8282
def default(session):
8383
# Install all test dependencies, then install this package in-place.
84+
8485
constraints_path = str(
8586
CURRENT_DIRECTORY / "testing" / f"constraints-{session.python}.txt"
8687
)
@@ -143,19 +144,15 @@ def system(session):
143144
constraints_path = str(
144145
CURRENT_DIRECTORY / "testing" / f"constraints-{session.python}.txt"
145146
)
146-
147147
system_test_path = os.path.join("tests", "system.py")
148148
system_test_folder_path = os.path.join("tests", "system")
149149

150150
# Check the value of `RUN_SYSTEM_TESTS` env var. It defaults to true.
151151
if os.environ.get("RUN_SYSTEM_TESTS", "true") == "false":
152152
session.skip("RUN_SYSTEM_TESTS is set to false, skipping")
153-
# Sanity check: Only run tests if the environment variable is set.
154-
if not os.environ.get("GOOGLE_APPLICATION_CREDENTIALS", ""):
155-
session.skip("Credentials must be set via environment variable")
156153
# Install pyopenssl for mTLS testing.
157154
if os.environ.get("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false") == "true":
158-
session.install("pyopenssl", "-c", constraints_path)
155+
session.install("pyopenssl")
159156

160157
system_test_exists = os.path.exists(system_test_path)
161158
system_test_folder_exists = os.path.exists(system_test_folder_path)
@@ -208,7 +205,7 @@ def docs(session):
208205
"""Build the docs for this library."""
209206

210207
session.install("-e", ".")
211-
session.install("sphinx", "alabaster", "recommonmark")
208+
session.install("sphinx==4.0.1", "alabaster", "recommonmark")
212209

213210
shutil.rmtree(os.path.join("docs", "_build"), ignore_errors=True)
214211
session.run(
@@ -230,7 +227,9 @@ def docfx(session):
230227
"""Build the docfx yaml files for this library."""
231228

232229
session.install("-e", ".")
233-
session.install("sphinx", "alabaster", "recommonmark", "gcp-sphinx-docfx-yaml")
230+
session.install(
231+
"sphinx==4.0.1", "alabaster", "recommonmark", "gcp-sphinx-docfx-yaml"
232+
)
234233

235234
shutil.rmtree(os.path.join("docs", "_build"), ignore_errors=True)
236235
session.run(

owlbot.py

Lines changed: 60 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,18 +86,75 @@ def get_staging_dirs(
8686
templated_files = common.py_library(
8787
samples=True, # set to True only if there are samples
8888
microgenerator=True,
89-
cov_level=99
89+
cov_level=100,
9090
)
9191

92-
s.move(templated_files, excludes=[".coveragerc", "noxfile.py"])
92+
s.move(templated_files, excludes=[".coveragerc"])
93+
94+
# ----------------------------------------------------------------------------
95+
# Customize noxfile.py
96+
# ----------------------------------------------------------------------------
97+
98+
def place_before(path, text, *before_text, escape=None):
99+
replacement = "\n".join(before_text) + "\n" + text
100+
if escape:
101+
for c in escape:
102+
text = text.replace(c, '\\' + c)
103+
s.replace([path], text, replacement)
104+
105+
system_emulated_session = """
106+
@nox.session(python="3.8")
107+
def system_emulated(session):
108+
import subprocess
109+
import signal
110+
111+
try:
112+
subprocess.call(["gcloud", "--version"])
113+
except OSError:
114+
session.skip("gcloud not found but required for emulator support")
115+
116+
# Currently, CI/CD doesn't have beta component of gcloud.
117+
subprocess.call(["gcloud", "components", "install", "beta", "bigtable"])
118+
119+
hostport = "localhost:8789"
120+
p = subprocess.Popen(
121+
["gcloud", "beta", "emulators", "bigtable", "start", "--host-port", hostport]
122+
)
123+
124+
session.env["BIGTABLE_EMULATOR_HOST"] = hostport
125+
system(session)
126+
127+
# Stop Emulator
128+
os.killpg(os.getpgid(p.pid), signal.SIGTERM)
129+
130+
"""
131+
132+
place_before(
133+
"noxfile.py",
134+
"@nox.session(python=SYSTEM_TEST_PYTHON_VERSIONS)\n"
135+
"def system(session):",
136+
system_emulated_session,
137+
escape="()"
138+
)
139+
140+
# add system_emulated nox session
141+
s.replace("noxfile.py",
142+
"""nox.options.sessions = \[
143+
"unit",
144+
"system",""",
145+
"""nox.options.sessions = [
146+
"unit",
147+
"system_emulated",
148+
"system",""",
149+
)
93150

94151
# ----------------------------------------------------------------------------
95152
# Samples templates
96153
# ----------------------------------------------------------------------------
97154

98155
sample_files = common.py_samples(samples=True)
99156
for path in sample_files:
100-
s.move(path, excludes=['noxfile.py'])
157+
s.move(path)
101158

102159

103160
s.shell.run(["nox", "-s", "blacken"], hide_output=False)

tests/system.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,9 @@ def setUpModule():
144144

145145
# After listing, create the test instances.
146146
admin_op = Config.INSTANCE.create(clusters=[Config.CLUSTER])
147-
admin_op.result(timeout=10)
147+
admin_op.result(timeout=30)
148148
data_op = Config.INSTANCE_DATA.create(clusters=[Config.CLUSTER_DATA])
149-
data_op.result(timeout=10)
149+
data_op.result(timeout=30)
150150

151151

152152
def tearDownModule():
@@ -203,7 +203,7 @@ def test_create_instance_defaults(self):
203203
self.instances_to_delete.append(instance)
204204

205205
# We want to make sure the operation completes.
206-
operation.result(timeout=10)
206+
operation.result(timeout=30)
207207

208208
# Create a new instance instance and make sure it is the same.
209209
instance_alt = Config.CLIENT.instance(ALT_INSTANCE_ID)
@@ -232,7 +232,7 @@ def test_create_instance(self):
232232
self.instances_to_delete.append(instance)
233233

234234
# We want to make sure the operation completes.
235-
operation.result(timeout=10)
235+
operation.result(timeout=30)
236236

237237
# Create a new instance instance and make sure it is the same.
238238
instance_alt = Config.CLIENT.instance(ALT_INSTANCE_ID)
@@ -675,7 +675,7 @@ def test_update_display_name_and_labels(self):
675675
operation = Config.INSTANCE.update()
676676

677677
# We want to make sure the operation completes.
678-
operation.result(timeout=10)
678+
operation.result(timeout=30)
679679

680680
# Create a new instance instance and reload it.
681681
instance_alt = Config.CLIENT.instance(INSTANCE_ID, labels=LABELS)
@@ -692,7 +692,7 @@ def test_update_display_name_and_labels(self):
692692
operation = Config.INSTANCE.update()
693693

694694
# We want to make sure the operation completes.
695-
operation.result(timeout=10)
695+
operation.result(timeout=30)
696696

697697
def test_update_type(self):
698698
from google.cloud.bigtable.enums import Instance
@@ -709,7 +709,7 @@ def test_update_type(self):
709709
self.instances_to_delete.append(instance)
710710

711711
# We want to make sure the operation completes.
712-
operation.result(timeout=10)
712+
operation.result(timeout=30)
713713

714714
# Unset the display_name
715715
instance.display_name = None
@@ -718,7 +718,7 @@ def test_update_type(self):
718718
operation = instance.update()
719719

720720
# We want to make sure the operation completes.
721-
operation.result(timeout=10)
721+
operation.result(timeout=30)
722722

723723
# Create a new instance instance and reload it.
724724
instance_alt = Config.CLIENT.instance(ALT_INSTANCE_ID)
@@ -734,7 +734,7 @@ def test_update_cluster(self):
734734
operation = Config.CLUSTER.update()
735735

736736
# We want to make sure the operation completes.
737-
operation.result(timeout=10)
737+
operation.result(timeout=30)
738738

739739
# Create a new cluster instance and reload it.
740740
alt_cluster = Config.INSTANCE.cluster(CLUSTER_ID)
@@ -745,7 +745,7 @@ def test_update_cluster(self):
745745
# other test cases.
746746
Config.CLUSTER.serve_nodes = SERVE_NODES
747747
operation = Config.CLUSTER.update()
748-
operation.result(timeout=20)
748+
operation.result(timeout=30)
749749

750750
def test_create_cluster(self):
751751
from google.cloud.bigtable.enums import StorageType
@@ -1084,7 +1084,7 @@ def test_backup(self):
10841084
self.assertFalse(temp_backup.exists())
10851085

10861086
# Testing `Backup.create()` method
1087-
temp_backup.create().result()
1087+
temp_backup.create().result(timeout=30)
10881088

10891089
# Implicit testing of `Backup.delete()` method
10901090
self.backups_to_delete.append(temp_backup)
@@ -1120,7 +1120,7 @@ def test_backup(self):
11201120
restored_table = Config.INSTANCE_DATA.table(restored_table_id)
11211121
temp_table.restore(
11221122
restored_table_id, cluster_id=CLUSTER_ID_DATA, backup_id=temp_backup_id,
1123-
).result()
1123+
).result(timeout=30)
11241124
tables = Config.INSTANCE_DATA.list_tables()
11251125
self.assertIn(restored_table, tables)
11261126
restored_table.delete()
@@ -1134,10 +1134,10 @@ def test_backup(self):
11341134
cluster_id=alt_cluster_id, location_id=LOCATION_ID, serve_nodes=SERVE_NODES,
11351135
)
11361136
if not Config.IN_EMULATOR:
1137-
alt_instance.create(clusters=[alt_cluster]).result(timeout=10)
1137+
alt_instance.create(clusters=[alt_cluster]).result(timeout=30)
11381138

11391139
# Testing `restore()`...
1140-
temp_backup.restore(restored_table_id, alt_instance_id).result()
1140+
temp_backup.restore(restored_table_id, alt_instance_id).result(timeout=30)
11411141
restored_table = alt_instance.table(restored_table_id)
11421142
self.assertIn(restored_table, alt_instance.list_tables())
11431143
restored_table.delete()

0 commit comments

Comments
 (0)
0