Download:
child 146:763646a08785
parent 144:e9e0737e1b6e
145:9c65d66fcda1
Anton Shestakov <av6@dwimlabs.net>, Sun, 17 Jul 2016 05:23:08 +0800
utils: adopt now() (renamed to timestamp()) and parse_timestamp(), test them

4 файлов изменено, 23 вставок(+), 15 удалений(-) [+]
candolint/utils.py file | annotate | diff | comparison | revisions
checker.py file | annotate | diff | comparison | revisions
incoming.py file | annotate | diff | comparison | revisions
tests/test_utils.py file | annotate | diff | comparison | revisions
--- a/candolint/utils.py Sun Jul 17 05:10:35 2016 +0800
+++ b/candolint/utils.py Sun Jul 17 05:23:08 2016 +0800
@@ -1,8 +1,17 @@
from __future__ import absolute_import
+from datetime import datetime
from os.path import abspath, dirname, join
def rel(*parts):
return abspath(join(dirname(dirname(__file__)), *parts))
+
+
+def timestamp():
+ return datetime.utcnow().strftime('%Y-%m-%dT%H:%M:%S+00:00')
+
+
+def parse_timestamp(value):
+ return datetime.strptime(value, '%Y-%m-%dT%H:%M:%S+00:00')
--- a/checker.py Sun Jul 17 05:10:35 2016 +0800
+++ b/checker.py Sun Jul 17 05:23:08 2016 +0800
@@ -3,7 +3,6 @@
import os
from argparse import ArgumentParser, FileType
-from datetime import datetime
from fnmatch import fnmatchcase
from shutil import rmtree
from subprocess import check_call, check_output, CalledProcessError
@@ -11,7 +10,7 @@
import yaml
-from candolint.utils import rel
+from candolint.utils import rel, timestamp
def run_ignore_codes(fn, args, codes):
@@ -44,10 +43,6 @@
return False
-def now():
- return datetime.utcnow().strftime('%Y-%m-%dT%H:%M:%S+00:00')
-
-
def read_linter_config(name, path=rel('linters')):
try:
fd = open(os.path.join(path, '{}.yml'.format(name)))
@@ -234,7 +229,7 @@
def wrapper(config):
- print('# C&O job started: {}'.format(now()))
+ print('# C&O job started: {}'.format(timestamp()))
tmp = mkdtemp(prefix='candolint.')
if not execute(tmp, config):
@@ -243,12 +238,12 @@
print('# C&O task: cleanup')
rmtree(tmp)
- print('# C&O job finished: {}'.format(now()))
+ print('# C&O job finished: {}'.format(timestamp()))
def bad_exit():
print('# C&O job failed (exception not caught)')
- print('# C&O job finished: {}'.format(now()))
+ print('# C&O job finished: {}'.format(timestamp()))
def main():
--- a/incoming.py Sun Jul 17 05:10:35 2016 +0800
+++ b/incoming.py Sun Jul 17 05:23:08 2016 +0800
@@ -5,17 +5,12 @@
import re
import sys
from argparse import ArgumentParser, FileType
-from datetime import datetime
from urlparse import urlparse
from tornado.escape import json_encode
from candolint.models import database, Project, Change, Check
-from candolint.utils import rel
-
-
-def parse_timestamp(value):
- return datetime.strptime(value, '%Y-%m-%dT%H:%M:%S+00:00')
+from candolint.utils import parse_timestamp, rel
def parse_project_url(url):
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test_utils.py Sun Jul 17 05:23:08 2016 +0800
@@ -0,0 +1,9 @@
+from datetime import datetime
+
+from candolint.utils import parse_timestamp, timestamp
+
+
+def test_timestamp_and_parse():
+ result = parse_timestamp(timestamp())
+ assert isinstance(result, datetime)
+ assert result.utcoffset() is None