Skip to content

Commit 8cea4b4

Browse files
committed
fix timestamp and module list issue
1 parent b4a83ea commit 8cea4b4

File tree

3 files changed

+24
-14
lines changed

3 files changed

+24
-14
lines changed

obspy_github_api/obspy_github_api.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
import github3
1313

14-
1514
# regex pattern in comments for requesting a docs build
1615
PATTERN_DOCS_BUILD = r"\+DOCS"
1716
# regex pattern in comments for requesting tests of specific submodules
@@ -30,7 +29,7 @@ def get_github_client(token=None):
3029
if token is None:
3130
msg = (
3231
"Could not get authorization token for ObsPy github API "
33-
"(env variable OBSPY_COMMIT_STATUS_TOKEN)"
32+
"(env variable GITHUB_TOKEN)"
3433
)
3534
warnings.warn(msg)
3635
gh = github3.GitHub()
@@ -223,9 +222,9 @@ def get_commit_time(commit, fork="obspy", token=None):
223222
repo = gh.repository(fork, "obspy")
224223
commit = repo.commit(commit)
225224
dt = datetime.datetime.strptime(
226-
commit.commit.committer["date"], "%Y-%m-%dT%H:%M:%SZ"
225+
commit.commit["committer"]["date"], "%Y-%m-%dT%H:%M:%SZ"
227226
)
228-
return time.mktime(dt.timetuple())
227+
return dt.timestamp()
229228

230229

231230
def get_issue_numbers_that_request_docs_build(verbose=False, token=None):
@@ -460,17 +459,20 @@ def make_ci_json_config(issue_number, path="obspy_ci_conf.json", token=None):
460459
# comment string to use for later actions.
461460
module_list = get_module_test_list(issue_number, token=token)
462461
docs = check_docs_build_requested(issue_number, token=token)
462+
module_list_obspy_prepended = [f"obspy.{x}" for x in module_list]
463463

464464
out = dict(
465-
module_list=("obspy." + ",obspy.").join(module_list),
465+
module_list=",".join(module_list_obspy_prepended),
466466
module_list_spaces=" ".join(module_list),
467467
docs=docs,
468468
)
469469

470-
# make sure path exists
471-
path = Path(path)
472-
path_dir = path if path.is_dir() else path.parent
473-
path_dir.mkdir(exist_ok=True, parents=True)
470+
# Write output to file if path is not None
471+
if path is not None:
472+
path = Path(path)
473+
path_dir = path if path.is_dir() else path.parent
474+
path_dir.mkdir(exist_ok=True, parents=True)
475+
with path.open("w") as fi:
476+
json.dump(out, fi, indent=4)
474477

475-
with path.open("w") as fi:
476-
json.dump(out, fi, indent=4)
478+
return out

obspy_github_api/tests/test_cli.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
"""
22
Tests for command line interface.
33
"""
4-
import contextlib
54
import json
6-
import unittest
75
import tempfile
86
from pathlib import Path
97
from subprocess import run

obspy_github_api/tests/test_obspy_github_api.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
get_commit_time,
99
get_issue_numbers_that_request_docs_build,
1010
get_module_test_list,
11+
make_ci_json_config,
1112
)
1213

1314

@@ -62,11 +63,20 @@ def test_get_commit_status():
6263

6364
def test_get_commit_time():
6465
sha = "f74e0f5bcf26a47df6138c1ce026d9d14d68c4d7"
65-
assert get_commit_time(sha) == 1471873965.0
66+
assert get_commit_time(sha) == 1471906365.0
6667

6768

6869
def test_get_issue_numbers_that_request_docs_build():
6970
issues = get_issue_numbers_that_request_docs_build()
7071
assert isinstance(issues, list)
7172
for issue in issues:
7273
assert isinstance(issue, int)
74+
75+
76+
def test_json_ci_config():
77+
"""Tests contents of configuration dict."""
78+
config_dict = make_ci_json_config(100, path=None)
79+
assert isinstance(config_dict, dict)
80+
# ensure module list elements don't end in '.'
81+
module_list_split = config_dict["module_list"].split(",")
82+
assert all([not x.endswith(".") for x in module_list_split])

0 commit comments

Comments
 (0)