Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# utcnow
tz_hour = time.timezone // 3600
utc_offset = str(tz_hour) if tz_hour < 0 else '+' + str(tz_hour)
stamp = time.strftime('%Y-%m-%dT%H%M%S') + utc_offset
return stamp
else:
raise ValueError('only iso8601 is accepted for now')
if __name__ == '__main__':
"""
CommandLine:
xdoctest -m ubelt.util_time
"""
import xdoctest as xdoc
xdoc.doctest_module(__file__)
def _test_status(docstr):
docstr = utils.codeblock(docstr)
try:
temp = utils.util_misc.TempDoctest(docstr=docstr)
except Exception:
# pytest seems to load an older version of xdoctest for some reason
import xdoctest
import inspect
print('xdoctest.__version__ = {!r}'.format(xdoctest.__version__))
print('utils = {!r}'.format(utils))
print('utils.util_misc = {!r}'.format(utils.util_misc))
print('utils.TempDoctest = {!r}'.format(utils.TempDoctest))
print(inspect.getargspec(utils.TempDoctest))
raise
doctests = list(core.parse_doctestables(temp.modpath))
status = doctests[0].run(verbose=0, on_error='return')
return status
# for optpart in options.split(','):
# if optpart:
# directive = parse_directive_optstr(optpart)
# if directive is not None:
# default_runtime_state[directive.name] = directive.positive
# # Specify a default doctest_example.Config state
# config = {
# 'default_runtime_state': default_runtime_state,
# offset_linenos = ns['offset_linenos']
# 'offset_linenos': offset_linenos,
# colored = ns['colored']
# 'colored': colored,
# }
xdoctest.doctest_module(modname, argv=[command], style=style,
config=config, durations=durations)
def _test_status(docstr):
docstr = utils.codeblock(docstr)
try:
temp = utils.util_misc.TempDoctest(docstr=docstr)
except Exception:
# pytest seems to load an older version of xdoctest for some reason
import xdoctest
import inspect
print('xdoctest.__version__ = {!r}'.format(xdoctest.__version__))
print('utils = {!r}'.format(utils))
print('utils.util_misc = {!r}'.format(utils.util_misc))
print('utils.TempDoctest = {!r}'.format(utils.TempDoctest))
print(inspect.getargspec(utils.TempDoctest))
raise
doctests = list(core.parse_doctestables(temp.modpath))
status = doctests[0].run(verbose=0, on_error='return')
return status
def test_parse_eval_single_want():
string = utils.codeblock(
'''
>>> a = 1
>>> 1 / 0
We have a want
''')
self = parser.DoctestParser()
parts = self.parse(string)
raw_source_lines = string.split('\n')[:-1]
ps1_linenos, eval_final = self._locate_ps1_linenos(raw_source_lines)
assert ps1_linenos == [0, 1]
assert eval_final
# Only one part because there is no want
assert len(parts) == 2
def test_retain_source():
"""
"""
source = utils.codeblock(
'''
>>> x = 2
>>> print("foo")
foo
''')
source_lines = source.split('\n')[:-1]
self = parser.DoctestParser()
linenos, eval_final = self._locate_ps1_linenos(source_lines)
assert eval_final
assert linenos == [0, 1]
p1, p2 = self.parse(source)
assert p1.source == 'x = 2'
assert p2.source == 'print("foo")'
def biz():
"""
multiline 1-1-0 """
class Spam(object):
""" multiline 0-2-1
---
"""
def eggs():
""" multiline 0-2-0
---"""
pass
''')
self = static.TopLevelVisitor.parse(source)
calldefs = self.calldefs
sourcelines = source.split('\n')
for k, calldef in calldefs.items():
line = sourcelines[calldef.lineno - 1]
callname = calldef.callname
# Ensure linenumbers correspond with start of func/class def
assert callname.split('.')[-1] in line
docsrc_lines = sourcelines[calldef.doclineno - 1:calldef.doclineno_end]
# Ensure linenumbers correspond with start and end of doctest
assert docsrc_lines[0].strip().startswith('"""')
assert docsrc_lines[-1].strip().endswith('"""')
def test_mod_globals():
with utils.TempDir() as temp:
dpath = temp.dpath
modpath = join(dpath, 'test_mod_globals.py')
source = utils.codeblock(
'''
X = 10
def test(self):
"""
>>> X
10
"""
''')
with open(modpath, 'w') as file:
file.write(source)
from xdoctest import core
doctests = list(core.parse_doctestables(modpath, style='freeform'))
assert len(doctests) == 1
def test_mod_lineno():
with utils.TempDir() as temp:
dpath = temp.dpath
modpath = join(dpath, 'test_mod_lineno.py')
source = utils.codeblock(
'''
class Fun(object): #1
@property
def test(self):
""" # 4
>>> a = 1
>>> 1 / 0
"""
''')
with open(modpath, 'w') as file:
file.write(source)
doctests = list(core.parse_doctestables(modpath, style='freeform'))
assert len(doctests) == 1
def test_ps1_linenos_3():
source_lines = ub.codeblock(
'''
>>> x = """
x = 2
"""
>>> y = (x.strip() + '1')
'x = 21'
''').split('\n')[:-1]
self = doctest_parser.DoctestParser()
linenos, eval_final = self._locate_ps1_linenos(source_lines)
assert not eval_final
assert linenos == [0, 3]