mirror of
https://github.com/GothenburgBitFactory/timewarrior.git
synced 2025-06-26 10:54:28 +02:00
fix pydoc, coding style, optimize imports
This commit is contained in:
parent
cdaf921e75
commit
81a7bba721
5 changed files with 25 additions and 31 deletions
|
@ -1,7 +1,8 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
import unittest
|
|
||||||
import sys
|
import sys
|
||||||
|
import unittest
|
||||||
|
|
||||||
|
|
||||||
class BaseTestCase(unittest.TestCase):
|
class BaseTestCase(unittest.TestCase):
|
||||||
def tap(self, out):
|
def tap(self, out):
|
||||||
|
@ -10,6 +11,7 @@ class BaseTestCase(unittest.TestCase):
|
||||||
sys.stderr.write(line + '\n')
|
sys.stderr.write(line + '\n')
|
||||||
sys.stderr.write("--- tap output end ---\n")
|
sys.stderr.write("--- tap output end ---\n")
|
||||||
|
|
||||||
|
|
||||||
class TestCase(BaseTestCase):
|
class TestCase(BaseTestCase):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
|
@ -7,9 +7,10 @@ import shlex
|
||||||
import shutil
|
import shutil
|
||||||
import tempfile
|
import tempfile
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
|
from .compat import STRING_TYPE
|
||||||
from .exceptions import CommandError
|
from .exceptions import CommandError
|
||||||
from .utils import run_cmd_wait, run_cmd_wait_nofail, which, timew_binary_location, DEFAULT_EXTENSION_PATH
|
from .utils import run_cmd_wait, run_cmd_wait_nofail, which, timew_binary_location, DEFAULT_EXTENSION_PATH
|
||||||
from .compat import STRING_TYPE
|
|
||||||
|
|
||||||
|
|
||||||
class Timew(object):
|
class Timew(object):
|
||||||
|
|
|
@ -1,14 +1,15 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
from __future__ import division
|
from __future__ import division
|
||||||
import os
|
|
||||||
import sys
|
|
||||||
import socket
|
|
||||||
import signal
|
|
||||||
import functools
|
|
||||||
import atexit
|
import atexit
|
||||||
|
import functools
|
||||||
|
import os
|
||||||
|
import signal
|
||||||
|
import sys
|
||||||
import tempfile
|
import tempfile
|
||||||
from subprocess import Popen, PIPE, STDOUT
|
from subprocess import Popen, PIPE, STDOUT
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from Queue import Queue, Empty
|
from Queue import Queue, Empty
|
||||||
except ImportError:
|
except ImportError:
|
||||||
|
@ -50,21 +51,18 @@ UUID_REGEXP = ("[0-9A-Fa-f]{8}-" + ("[0-9A-Fa-f]{4}-" * 3) + "[0-9A-Fa-f]{12}")
|
||||||
|
|
||||||
|
|
||||||
def timew_binary_location(cmd="timew"):
|
def timew_binary_location(cmd="timew"):
|
||||||
""" ../src/ is used by default.
|
""" ../src/ is used by default."""
|
||||||
"""
|
|
||||||
return os.path.join(BIN_PREFIX, cmd)
|
return os.path.join(BIN_PREFIX, cmd)
|
||||||
return binary_location(cmd, TIMEW_USE_PATH)
|
return binary_location(cmd, TIMEW_USE_PATH)
|
||||||
|
|
||||||
|
|
||||||
def binary_location(cmd, USE_PATH=False):
|
def binary_location(cmd, USE_PATH=False):
|
||||||
""" ../src/ is used by default.
|
""" ../src/ is used by default."""
|
||||||
"""
|
|
||||||
return os.path.join(BIN_PREFIX, cmd)
|
return os.path.join(BIN_PREFIX, cmd)
|
||||||
|
|
||||||
|
|
||||||
def wait_condition(cond, timeout=1, sleeptime=.01):
|
def wait_condition(cond, timeout=1, sleeptime=.01):
|
||||||
"""Wait for condition to return anything other than None
|
"""Wait for condition to return anything other than None"""
|
||||||
"""
|
|
||||||
# NOTE Increasing sleeptime can dramatically increase testsuite runtime
|
# NOTE Increasing sleeptime can dramatically increase testsuite runtime
|
||||||
# It also reduces CPU load significantly
|
# It also reduces CPU load significantly
|
||||||
if timeout is None:
|
if timeout is None:
|
||||||
|
@ -89,8 +87,7 @@ def wait_condition(cond, timeout=1, sleeptime=.01):
|
||||||
|
|
||||||
|
|
||||||
def wait_process(pid, timeout=None):
|
def wait_process(pid, timeout=None):
|
||||||
"""Wait for process to finish
|
"""Wait for process to finish"""
|
||||||
"""
|
|
||||||
def process():
|
def process():
|
||||||
try:
|
try:
|
||||||
os.kill(pid, 0)
|
os.kill(pid, 0)
|
||||||
|
@ -138,8 +135,7 @@ def _queue_output(arguments, pidq, outputq):
|
||||||
|
|
||||||
|
|
||||||
def _retrieve_output(thread, timeout, queue, thread_error):
|
def _retrieve_output(thread, timeout, queue, thread_error):
|
||||||
"""Fetch output from binary subprocess queues
|
"""Fetch output from binary subprocess queues"""
|
||||||
"""
|
|
||||||
# Try to join the thread on failure abort
|
# Try to join the thread on failure abort
|
||||||
thread.join(timeout)
|
thread.join(timeout)
|
||||||
if thread.isAlive():
|
if thread.isAlive():
|
||||||
|
@ -213,7 +209,7 @@ def _get_output(arguments, timeout=None):
|
||||||
|
|
||||||
def run_cmd_wait(cmd, input=None, stdout=PIPE, stderr=PIPE,
|
def run_cmd_wait(cmd, input=None, stdout=PIPE, stderr=PIPE,
|
||||||
merge_streams=False, env=os.environ, timeout=None):
|
merge_streams=False, env=os.environ, timeout=None):
|
||||||
"Run a subprocess and wait for it to finish"
|
"""Run a subprocess and wait for it to finish"""
|
||||||
|
|
||||||
if input is None:
|
if input is None:
|
||||||
stdin = None
|
stdin = None
|
||||||
|
@ -252,7 +248,7 @@ def run_cmd_wait(cmd, input=None, stdout=PIPE, stderr=PIPE,
|
||||||
|
|
||||||
|
|
||||||
def run_cmd_wait_nofail(*args, **kwargs):
|
def run_cmd_wait_nofail(*args, **kwargs):
|
||||||
"Same as run_cmd_wait but silence the exception if it happens"
|
"""Same as run_cmd_wait but silence the exception if it happens"""
|
||||||
try:
|
try:
|
||||||
return run_cmd_wait(*args, **kwargs)
|
return run_cmd_wait(*args, **kwargs)
|
||||||
except CommandError as e:
|
except CommandError as e:
|
||||||
|
@ -260,8 +256,7 @@ def run_cmd_wait_nofail(*args, **kwargs):
|
||||||
|
|
||||||
|
|
||||||
def memoize(obj):
|
def memoize(obj):
|
||||||
"""Keep an in-memory cache of function results given it's inputs
|
"""Keep an in-memory cache of function results given it's inputs"""
|
||||||
"""
|
|
||||||
cache = obj.cache = {}
|
cache = obj.cache = {}
|
||||||
|
|
||||||
@functools.wraps(obj)
|
@functools.wraps(obj)
|
||||||
|
@ -343,8 +338,7 @@ except ImportError:
|
||||||
|
|
||||||
|
|
||||||
def parse_datafile(file):
|
def parse_datafile(file):
|
||||||
"""Parse .data files, treating files as JSON
|
"""Parse .data files, treating files as JSON"""
|
||||||
"""
|
|
||||||
data = []
|
data = []
|
||||||
with open(file) as fh:
|
with open(file) as fh:
|
||||||
for line in fh:
|
for line in fh:
|
||||||
|
@ -362,9 +356,7 @@ def parse_datafile(file):
|
||||||
|
|
||||||
|
|
||||||
def mkstemp(data):
|
def mkstemp(data):
|
||||||
"""
|
"""Create a temporary file that is removed at process exit"""
|
||||||
Create a temporary file that is removed at process exit
|
|
||||||
"""
|
|
||||||
def rmtemp(name):
|
def rmtemp(name):
|
||||||
try:
|
try:
|
||||||
os.remove(name)
|
os.remove(name)
|
||||||
|
@ -382,8 +374,7 @@ def mkstemp(data):
|
||||||
|
|
||||||
|
|
||||||
def mkstemp_exec(data):
|
def mkstemp_exec(data):
|
||||||
"""Create a temporary executable file that is removed at process exit
|
"""Create a temporary executable file that is removed at process exit"""
|
||||||
"""
|
|
||||||
name = mkstemp(data)
|
name = mkstemp(data)
|
||||||
os.chmod(name, 0o755)
|
os.chmod(name, 0o755)
|
||||||
|
|
||||||
|
|
|
@ -27,12 +27,12 @@
|
||||||
|
|
||||||
# Original version by Renato Alves
|
# Original version by Renato Alves
|
||||||
|
|
||||||
|
import inspect
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
import traceback
|
||||||
import unittest
|
import unittest
|
||||||
import warnings
|
import warnings
|
||||||
import traceback
|
|
||||||
import inspect
|
|
||||||
|
|
||||||
|
|
||||||
def color(text, c):
|
def color(text, c):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue