9 new revisions:
Revision: 84d01fe8ba67
Author: Pekka Klärck
Date: Sat Jun 18 11:05:14 2011
Log: whitespace
http://code.google.com/p/robotframework/source/detail?r=84d01fe8ba67
Revision: a571af11d4ef
Author: Pekka Klärck
Date: Sat Jun 18 11:28:47 2011
Log: OutputSplitter: refactored to ease adding timestamp support...
http://code.google.com/p/robotframework/source/detail?r=a571af11d4ef
Revision: 66520ab1c5dc
Author: Pekka Klärck
Date: Sat Jun 18 12:39:31 2011
Log: enhanced and cleaned up output splitter tests
http://code.google.com/p/robotframework/source/detail?r=66520ab1c5dc
Revision: fd403dcd40ba
Author: Pekka Klärck
Date: Sat Jun 18 12:47:40 2011
Log: Unit tests and implementation for giving timestamp when logging
throug...
http://code.google.com/p/robotframework/source/detail?r=fd403dcd40ba
Revision: 4be095f0be1f
Author: Pekka Klärck
Date: Sat Jun 18 13:40:33 2011
Log: cleanup
http://code.google.com/p/robotframework/source/detail?r=4be095f0be1f
Revision: bc16b0d48f98
Author: Pekka Klärck
Date: Sat Jun 18 14:14:55 2011
Log: Fixed handling timestamps embedded to messages logged through
stdout....
http://code.google.com/p/robotframework/source/detail?r=bc16b0d48f98
Revision: 89569e438d9b
Author: Pekka Klärck
Date: Sat Jun 18 14:28:07 2011
Log: fixed secs_to_timestr when millis in given value round to seconds
http://code.google.com/p/robotframework/source/detail?r=89569e438d9b
Revision: 32532ff33f86
Author: Pekka Klärck
Date: Sat Jun 18 14:43:00 2011
Log: Acceptance tests for Python library logging messages through
stdout wi...
http://code.google.com/p/robotframework/source/detail?r=32532ff33f86
Revision: 9cab09c73806
Author: Pekka Klärck
Date: Sat Jun 18 15:00:50 2011
Log: Test adding timestamps to log messages via stdout also with Java
libs....
http://code.google.com/p/robotframework/source/detail?r=9cab09c73806
==============================================================================
Revision: 84d01fe8ba67
Author: Pekka Klärck
Date: Sat Jun 18 11:05:14 2011
Log: whitespace
http://code.google.com/p/robotframework/source/detail?r=84d01fe8ba67
Modified:
/utest/output/test_output_splitter.py
=======================================
--- /utest/output/test_output_splitter.py Sun May 30 07:42:26 2010
+++ /utest/output/test_output_splitter.py Sat Jun 18 11:05:14 2011
@@ -4,18 +4,18 @@
from robot.output.output import _OutputSplitter
-
+
class TestOutputSplitter(unittest.TestCase):
-
+
def test_empty_output_should_result_in_empty_messages_list(self):
splitter = _OutputSplitter('')
assert_equals([], list(splitter))
-
+
def test_plain_output_should_have_info_level(self):
splitter = _OutputSplitter('this is an output message\nin
many\nlines.')
assert_equals(1, len(list(splitter)))
self._verify_message(splitter, 'this is an output message\nin
many\nlines.')
-
+
def test_leading_and_trailing_space_should_be_stripped(self):
splitter = _OutputSplitter('\t \n My message \t\r\n')
self._verify_message(splitter, 'My message')
@@ -23,7 +23,7 @@
def test_legal_level_is_correctly_read(self):
splitter = _OutputSplitter('*DEBUG* My message details')
self._verify_message(splitter, 'My message details', 'DEBUG')
-
+
def test_it_is_possible_to_define_multiple_levels(self):
splitter = _OutputSplitter('*WARN*WARNING!\n*DEBUG*msg')
assert_equals(2, len(list(splitter)))
@@ -33,19 +33,18 @@
def
test_html_flag_should_be_parsed_correctly_and_uses_info_level(self):
splitter = _OutputSplitter('*HTML* <div><a href="">link</a></div>')
self._verify_message(splitter, '<div><a
href="">link</a></div>', 'INFO', True)
-
+
def test_default_level_for_first_message_in_info(self):
splitter = _OutputSplitter('<img src="foo bar">\n*DEBUG*bar foo')
self._verify_message(splitter, '<img src="foo bar">')
self._verify_message(splitter, 'bar foo', 'DEBUG', index=1)
-
-
+
def _verify_message(self, splitter, msg, level='INFO', html=False,
index=0):
message = list(splitter)[index]
assert_equals(message.message, msg)
assert_equals(message.level, level)
assert_equals(message.html, html)
-
+
if __name__ == '__main__':
unittest.main()
==============================================================================
Revision: a571af11d4ef
Author: Pekka Klärck
Date: Sat Jun 18 11:28:47 2011
Log: OutputSplitter: refactored to ease adding timestamp support
Update issue 456
Actual work started.
http://code.google.com/p/robotframework/source/detail?r=a571af11d4ef
Modified:
/src/robot/output/output.py
=======================================
--- /src/robot/output/output.py Wed Jun 15 04:01:03 2011
+++ /src/robot/output/output.py Sat Jun 18 11:28:47 2011
@@ -98,12 +98,16 @@
def _split_to_levels_and_messages(self, output):
tokens = self._split_from_levels.split(output)
- # Output started with a level
- if tokens[0] == '':
- tokens = tokens[1:]
- else:
- tokens.insert(0, '*INFO*')
+ tokens = self._add_initial_default_level_if_needed(tokens)
return ((tokens[i], tokens[i+1]) for i in xrange(0, len(tokens),
2))
+ def _add_initial_default_level_if_needed(self, tokens):
+ if self._output_started_with_level(tokens):
+ return tokens[1:]
+ return ['*INFO*'] + tokens
+
+ def _output_started_with_level(self, tokens):
+ return tokens[0] == ''
+
def __iter__(self):
return iter(self._messages)
==============================================================================
Revision: 66520ab1c5dc
Author: Pekka Klärck
Date: Sat Jun 18 12:39:31 2011
Log: enhanced and cleaned up output splitter tests
http://code.google.com/p/robotframework/source/detail?r=66520ab1c5dc
Modified:
/utest/output/test_output_splitter.py
=======================================
--- /utest/output/test_output_splitter.py Sat Jun 18 11:05:14 2011
+++ /utest/output/test_output_splitter.py Sat Jun 18 12:39:31 2011
@@ -9,35 +9,46 @@
def test_empty_output_should_result_in_empty_messages_list(self):
splitter = _OutputSplitter('')
- assert_equals([], list(splitter))
+ assert_equals(list(splitter), [])
def test_plain_output_should_have_info_level(self):
- splitter = _OutputSplitter('this is an output message\nin
many\nlines.')
- assert_equals(1, len(list(splitter)))
- self._verify_message(splitter, 'this is an output message\nin
many\nlines.')
+ splitter = _OutputSplitter('this is message\nin many\nlines.')
+ self._verify_message(splitter, 'this is message\nin many\nlines.')
+ assert_equals(len(list(splitter)), 1)
def test_leading_and_trailing_space_should_be_stripped(self):
splitter = _OutputSplitter('\t \n My message \t\r\n')
self._verify_message(splitter, 'My message')
+ assert_equals(len(list(splitter)), 1)
def test_legal_level_is_correctly_read(self):
splitter = _OutputSplitter('*DEBUG* My message details')
self._verify_message(splitter, 'My message details', 'DEBUG')
+ assert_equals(len(list(splitter)), 1)
+
+ def test_space_after_level_is_optional(self):
+ splitter = _OutputSplitter('*WARN*No space!')
+ self._verify_message(splitter, 'No space!', 'WARN')
+ assert_equals(len(list(splitter)), 1)
def test_it_is_possible_to_define_multiple_levels(self):
- splitter = _OutputSplitter('*WARN*WARNING!\n*DEBUG*msg')
- assert_equals(2, len(list(splitter)))
+ splitter = _OutputSplitter('*WARN* WARNING!\n'
+ '*TRACE*msg')
self._verify_message(splitter, 'WARNING!', 'WARN')
- self._verify_message(splitter, 'msg', 'DEBUG', index=1)
+ self._verify_message(splitter, 'msg', 'TRACE', index=1)
+ assert_equals(len(list(splitter)), 2)
def
test_html_flag_should_be_parsed_correctly_and_uses_info_level(self):
- splitter = _OutputSplitter('*HTML* <div><a href="">link</a></div>')
- self._verify_message(splitter, '<div><a
href="">link</a></div>', 'INFO', True)
-
- def test_default_level_for_first_message_in_info(self):
- splitter = _OutputSplitter('<img src="foo bar">\n*DEBUG*bar foo')
+ splitter = _OutputSplitter('*HTML* <b>Hello</b>')
+ self._verify_message(splitter, '<b>Hello</b>', level='INFO',
html=True)
+ assert_equals(len(list(splitter)), 1)
+
+ def test_default_level_for_first_message_is_info(self):
+ splitter = _OutputSplitter('<img src="foo bar">\n'
+ '*DEBUG*bar foo')
self._verify_message(splitter, '<img src="foo bar">')
self._verify_message(splitter, 'bar foo', 'DEBUG', index=1)
+ assert_equals(len(list(splitter)), 2)
def _verify_message(self, splitter, msg, level='INFO', html=False,
index=0):
message = list(splitter)[index]
==============================================================================
Revision: fd403dcd40ba
Author: Pekka Klärck
Date: Sat Jun 18 12:47:40 2011
Log: Unit tests and implementation for giving timestamp when logging
through stdout.
Update issue 456
Unit tests and implementation done. Will still create acceptance tests and
also User Guide needs to be updated.
http://code.google.com/p/robotframework/source/detail?r=fd403dcd40ba
Modified:
/src/robot/output/output.py
/src/robot/utils/robottime.py
/utest/output/test_output_splitter.py
=======================================
--- /src/robot/output/output.py Sat Jun 18 11:28:47 2011
+++ /src/robot/output/output.py Sat Jun 18 12:47:40 2011
@@ -84,30 +84,36 @@
class _OutputSplitter:
- _split_from_levels = re.compile('^(\*(?:%s|
HTML)\*)' % '|'.join(LEVELS),
- re.MULTILINE)
+ _split_from_levels = re.compile('^(?:\*'
+ '(%s|HTML)' # Level
+ '(:\d+(?:\.\d+)?)?' # Optional
timestamp
+ '\*)' % '|'.join(LEVELS), re.MULTILINE)
def __init__(self, output):
- self._messages = self._get_messages(output.strip())
+ self._messages = list(self._get_messages(output.strip()))
def _get_messages(self, output):
- if not output:
- return []
- return [Message(msg.strip(), level[1:-1])
- for level, msg in
self._split_to_levels_and_messages(output)]
-
- def _split_to_levels_and_messages(self, output):
+ for level, timestamp, msg in self._split_output(output):
+ if timestamp:
+ timestamp = self._format_timestamp(timestamp[1:])
+ yield Message(msg.strip(), level, timestamp=timestamp)
+
+ def _split_output(self, output):
tokens = self._split_from_levels.split(output)
- tokens = self._add_initial_default_level_if_needed(tokens)
- return ((tokens[i], tokens[i+1]) for i in xrange(0, len(tokens),
2))
-
- def _add_initial_default_level_if_needed(self, tokens):
+ tokens = self._add_initial_level_and_time_if_needed(tokens)
+ for i in xrange(0, len(tokens), 3):
+ yield tokens[i:i+3]
+
+ def _add_initial_level_and_time_if_needed(self, tokens):
if self._output_started_with_level(tokens):
return tokens[1:]
- return ['*INFO*'] + tokens
+ return ['INFO', None] + tokens
def _output_started_with_level(self, tokens):
return tokens[0] == ''
+ def _format_timestamp(self, millis):
+ return utils.format_time(round(float(millis)/1000))
+
def __iter__(self):
return iter(self._messages)
=======================================
--- /src/robot/utils/robottime.py Wed May 25 07:40:46 2011
+++ /src/robot/utils/robottime.py Sat Jun 18 12:47:40 2011
@@ -155,13 +155,19 @@
return sign, millis, secs, mins, hours, days
-def format_time(timetuple, daysep='', daytimesep=' ', timesep=':',
+def format_time(timetuple_or_epochsecs, daysep='', daytimesep=' ',
timesep=':',
millissep=None, gmtsep=None):
- """Returns a timestamp formatted from timetuple using separators.
-
- timetuple is (year, month, day, hour, min, sec[, millis]), where parts
must
+ """Returns a timestamp formatted from given time using separators.
+
+ Time can be given either as a timetuple or seconds after epoch.
+ Timetuple is (year, month, day, hour, min, sec[, millis]), where parts
must
be integers and millis is required only when millissep is not None.
+ Seconds after epoch can be either an integer or a float.
"""
+ if isinstance(timetuple_or_epochsecs, (int, long, float)):
+ timetuple = time.localtime(timetuple_or_epochsecs)
+ else:
+ timetuple = timetuple_or_epochsecs
daytimeparts = ['%02d' % t for t in timetuple[:6]]
day = daysep.join(daytimeparts[:3])
time_ = timesep.join(daytimeparts[3:6])
@@ -207,7 +213,7 @@
return int(time_)
timetuple = time.localtime(time_)
parts = []
- for i, match in enumerate(['year','month','day','hour','min','sec']):
+ for i, match in enumerate('year month day hour min sec'.split()):
if match in format:
parts.append('%.2d' % timetuple[i])
# 2) Return time as timestamp
=======================================
--- /utest/output/test_output_splitter.py Sat Jun 18 12:39:31 2011
+++ /utest/output/test_output_splitter.py Sat Jun 18 12:47:40 2011
@@ -1,6 +1,8 @@
import unittest
-
-from robot.utils.asserts import *
+import time
+
+from robot.utils.asserts import assert_equals
+from robot.utils import format_time
from robot.output.output import _OutputSplitter
@@ -50,11 +52,33 @@
self._verify_message(splitter, 'bar foo', 'DEBUG', index=1)
assert_equals(len(list(splitter)), 2)
- def _verify_message(self, splitter, msg, level='INFO', html=False,
index=0):
+ def test_timestamp_given_as_integer(self):
+ now = time.time()
+ splitter = _OutputSplitter('*INFO:xxx* No timestamp\n'
+ '*INFO:0* Epoch\n'
+ '*HTML:%d* X' % (now*1000))
+ self._verify_message(splitter, '*INFO:xxx* No timestamp')
+ self._verify_message(splitter, 'Epoch', timestamp=0, index=1)
+ self._verify_message(splitter, html=True, timestamp=now, index=2)
+ assert_equals(len(list(splitter)), 3)
+
+ def test_timestamp_given_as_float(self):
+ splitter = _OutputSplitter('*INFO:1x2* No timestamp\n'
+ '*HTML:1000.1* X\n'
+ '*INFO:123456789.12345* X')
+ self._verify_message(splitter, '*INFO:1x2* No timestamp')
+ self._verify_message(splitter, html=True, timestamp=1, index=1)
+ self._verify_message(splitter, timestamp=123457, index=2)
+ assert_equals(len(list(splitter)), 3)
+
+ def _verify_message(self, splitter, msg='X', level='INFO', html=False,
+ timestamp=None, index=0):
message = list(splitter)[index]
assert_equals(message.message, msg)
assert_equals(message.level, level)
assert_equals(message.html, html)
+ if timestamp:
+ assert_equals(message.timestamp, format_time(round(timestamp)))
if __name__ == '__main__':
==============================================================================
Revision: 4be095f0be1f
Author: Pekka Klärck
Date: Sat Jun 18 13:40:33 2011
Log: cleanup
http://code.google.com/p/robotframework/source/detail?r=4be095f0be1f
Modified:
/utest/utils/test_robottime.py
=======================================
--- /utest/utils/test_robottime.py Wed May 25 12:22:12 2011
+++ /utest/utils/test_robottime.py Sat Jun 18 13:40:33 2011
@@ -2,11 +2,14 @@
import sys
import re
import time
-from types import *
-
-from robot.utils.asserts import *
-
-from robot.utils.robottime import *
+
+from robot.utils.asserts import (assert_equal, assert_raises_with_msg,
+ assert_true, assert_not_none)
+
+from robot.utils.robottime import (timestr_to_secs, secs_to_timestr,
get_time,
+ parse_time, format_time,
get_elapsed_time,
+ get_timestamp, get_start_timestamp,
+ timestamp_to_secs)
EXAMPLE_TIME = time.mktime((2007, 9, 20, 16, 15, 14, 0, 0, -1))
@@ -49,7 +52,7 @@
(0, 0),
('0', 0),
('0day 0hour 0minute 0seconds 0millisecond', 0)]:
- assert_equals(timestr_to_secs(inp), exp, inp)
+ assert_equal(timestr_to_secs(inp), exp, inp)
def test_timestr_to_secs_invalid(self):
for inv in ['', 'foo', '1sec 42 millis 3', '1min 2w', None]:
@@ -78,15 +81,15 @@
(-1, '- 1s', '- 1 second'),
(-171967.667, '- 1d 23h 46min 7s 667ms',
'- 1 day 23 hours 46 minutes 7 seconds 667 milliseconds')]:
- assert_equals(secs_to_timestr(inp), verbose)
- assert_equals(secs_to_timestr(inp, compact=True), compact)
+ assert_equal(secs_to_timestr(inp), verbose)
+ assert_equal(secs_to_timestr(inp, compact=True), compact)
def test_format_time(self):
- tt = (2005, 11, 2, 14, 23, 12, 123) # timetuple
+ timetuple = (2005, 11, 2, 14, 23, 12, 123)
for seps, exp in [(('-',' ',':'), '2005-11-02 14:23:12'),
(('', '-', ''), '20051102-142312'),
(('-',' ',':','.'), '2005-11-02 14:23:12.123')]:
- assert_equals(format_time(tt, *seps), exp)
+ assert_equal(format_time(timetuple, *seps), exp)
def test_get_timestamp(self):
for seps, pattern in [((), '^\d{8} \d\d:\d\d:\d\d.\d\d\d$'),
@@ -101,18 +104,18 @@
def test_get_start_timestamp(self):
start = get_start_timestamp(millissep='.')
time.sleep(0.002)
- assert_equals(get_start_timestamp(millissep='.'), start)
+ assert_equal(get_start_timestamp(millissep='.'), start)
def test_timestamp_to_secs_with_default(self):
- assert_equals(timestamp_to_secs('20070920 16:15:14.123'),
EXAMPLE_TIME)
+ assert_equal(timestamp_to_secs('20070920 16:15:14.123'),
EXAMPLE_TIME)
def test_timestamp_to_secs_with_seps(self):
result = timestamp_to_secs('2007-09-20#16x15x14M123',
('-','#','x','M'))
- assert_equals(result, EXAMPLE_TIME)
+ assert_equal(result, EXAMPLE_TIME)
def test_timestamp_to_secs_with_millis(self):
result = timestamp_to_secs('20070920 16:15:14.123', millis=True)
- assert_equals(result, EXAMPLE_TIME + 0.123)
+ assert_equal(result, EXAMPLE_TIME + 0.123)
def test_get_elapsed_time_without_millis(self):
starttime = '20060526 14:01:10'
@@ -140,7 +143,7 @@
('20060601 14:01:11', 144*60*60+1),
('20070526 14:01:10', 8760*60*60)]:
actual = get_elapsed_time(starttime, endtime, seps)
- assert_equals(actual, expected*1000, endtime)
+ assert_equal(actual, expected*1000, endtime)
def test_get_elapsed_time_with_millis(self):
starttime = '20060526 14:01:10.500'
@@ -165,7 +168,7 @@
('20070526 14:01:10.499', 31535999999),
('20070526 14:01:10.500', 31536000000)]:
actual = get_elapsed_time(starttime, endtime, seps)
- assert_equals(actual, expected, endtime)
+ assert_equal(actual, expected, endtime)
def test_get_elapsed_time_negative_without_millis(self):
starttime = '20060526 14:01:10'
@@ -178,7 +181,7 @@
('20060521 14:01:10', -432000),
('20060521 14:01:09', -432000-1)]:
actual = get_elapsed_time(starttime, endtime, seps)
- assert_equals(actual, expected*1000, endtime)
+ assert_equal(actual, expected*1000, endtime)
def test_get_elapsed_time_negative_with_millis(self):
starttime = '20060526 14:01:10.500'
@@ -190,7 +193,7 @@
('20060526 14:01:09.500', -1000),
('20060526 14:01:09.499', -1001)]:
actual = get_elapsed_time(starttime, endtime, seps)
- assert_equals(actual, expected, endtime)
+ assert_equal(actual, expected, endtime)
def test_get_elapsed_time_separators(self):
startday = endday = ('2006','05','26')
@@ -214,7 +217,7 @@
end_stamp += m_sep + endmillis
seps = (d_sep, dt_sep, t_sep, m_sep)
actual = get_elapsed_time(start_stamp, end_stamp, seps)
- assert_equals(actual, 3599000)
+ assert_equal(actual, 3599000)
def test_get_elapsed_time_without_end_timestamp(self):
seps = ('-', ' ', ':', '.')
@@ -225,7 +228,7 @@
for input, expected in [('100', 100),
('2007-09-20 16:15:14', EXAMPLE_TIME),
('20070920 161514', EXAMPLE_TIME)]:
- assert_equals(parse_time(input), expected)
+ assert_equal(parse_time(input), expected)
def test_parse_modified_time_with_now(self):
for input, adjusted in [('now', 0),
==============================================================================
Revision: bc16b0d48f98
Author: Pekka Klärck
Date: Sat Jun 18 14:14:55 2011
Log: Fixed handling timestamps embedded to messages logged through
stdout.
Update issue 456
Initial acceptance tests revealed that implementation didn't really work.
Fixed unit tests, added some more unit tests, and obviously fixed also the
code.
http://code.google.com/p/robotframework/source/detail?r=bc16b0d48f98
Modified:
/src/robot/output/output.py
/src/robot/utils/robottime.py
/utest/output/test_output_splitter.py
/utest/utils/test_robottime.py
=======================================
--- /src/robot/output/output.py Sat Jun 18 12:47:40 2011
+++ /src/robot/output/output.py Sat Jun 18 14:14:55 2011
@@ -12,7 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-
import re
from robot.common.statistics import Statistics
@@ -113,7 +112,7 @@
return tokens[0] == ''
def _format_timestamp(self, millis):
- return utils.format_time(round(float(millis)/1000))
+ return utils.format_time(float(millis)/1000, millissep='.')
def __iter__(self):
return iter(self._messages)
=======================================
--- /src/robot/utils/robottime.py Sat Jun 18 12:47:40 2011
+++ /src/robot/utils/robottime.py Sat Jun 18 14:14:55 2011
@@ -18,18 +18,23 @@
from misc import plural_or_not
-def _get_time():
+def _get_timetuple(epoch_secs=None):
if _CURRENT_TIME:
return _CURRENT_TIME
- current = time.time()
- timetuple = time.localtime(current)[:6] # from year to secs
- millis = int((current - int(current)) * 1000)
- timetuple += (millis,)
- return timetuple
+ if epoch_secs is None: # can also be 0 (at least in unit tests)
+ epoch_secs = time.time()
+ secs, millis = _float_secs_to_secs_and_millis(epoch_secs)
+ timetuple = time.localtime(secs)[:6] # from year to secs
+ return timetuple + (millis,)
+
+def _float_secs_to_secs_and_millis(secs):
+ isecs = int(secs)
+ millis = int(round((secs - isecs) * 1000))
+ return (isecs, millis) if millis < 1000 else (isecs+1, 0)
_CURRENT_TIME = None # Seam for mocking time-dependent tests
-START_TIME = _get_time()
+START_TIME = _get_timetuple()
def timestr_to_secs(timestr):
@@ -160,12 +165,16 @@
"""Returns a timestamp formatted from given time using separators.
Time can be given either as a timetuple or seconds after epoch.
+
Timetuple is (year, month, day, hour, min, sec[, millis]), where parts
must
be integers and millis is required only when millissep is not None.
+ Notice that this is not 100% compatible with standard Python timetuples
+ which do not have millis.
+
Seconds after epoch can be either an integer or a float.
"""
if isinstance(timetuple_or_epochsecs, (int, long, float)):
- timetuple = time.localtime(timetuple_or_epochsecs)
+ timetuple = _get_timetuple(timetuple_or_epochsecs)
else:
timetuple = timetuple_or_epochsecs
daytimeparts = ['%02d' % t for t in timetuple[:6]]
@@ -264,8 +273,7 @@
def get_timestamp(daysep='', daytimesep=' ', timesep=':', millissep='.'):
- timetuple = _get_time()
- return format_time(timetuple, daysep, daytimesep, timesep, millissep)
+ return format_time(_get_timetuple(), daysep, daytimesep, timesep,
millissep)
def timestamp_to_secs(timestamp, seps=('', ' ', ':', '.'), millis=False):
=======================================
--- /utest/output/test_output_splitter.py Sat Jun 18 12:47:40 2011
+++ /utest/output/test_output_splitter.py Sat Jun 18 14:14:55 2011
@@ -53,7 +53,7 @@
assert_equals(len(list(splitter)), 2)
def test_timestamp_given_as_integer(self):
- now = time.time()
+ now = int(time.time())
splitter = _OutputSplitter('*INFO:xxx* No timestamp\n'
'*INFO:0* Epoch\n'
'*HTML:%d* X' % (now*1000))
@@ -64,11 +64,11 @@
def test_timestamp_given_as_float(self):
splitter = _OutputSplitter('*INFO:1x2* No timestamp\n'
- '*HTML:1000.1* X\n'
- '*INFO:123456789.12345* X')
+ '*HTML:1000.123456789* X\n'
+ '*INFO:12345678.9* X')
self._verify_message(splitter, '*INFO:1x2* No timestamp')
self._verify_message(splitter, html=True, timestamp=1, index=1)
- self._verify_message(splitter, timestamp=123457, index=2)
+ self._verify_message(splitter, timestamp=12345.679, index=2)
assert_equals(len(list(splitter)), 3)
def _verify_message(self, splitter, msg='X', level='INFO', html=False,
@@ -78,7 +78,8 @@
assert_equals(message.level, level)
assert_equals(message.html, html)
if timestamp:
- assert_equals(message.timestamp, format_time(round(timestamp)))
+ assert_equals(message.timestamp,
+ format_time(timestamp, millissep='.'))
if __name__ == '__main__':
=======================================
--- /utest/utils/test_robottime.py Sat Jun 18 13:40:33 2011
+++ /utest/utils/test_robottime.py Sat Jun 18 14:14:55 2011
@@ -9,7 +9,7 @@
from robot.utils.robottime import (timestr_to_secs, secs_to_timestr,
get_time,
parse_time, format_time,
get_elapsed_time,
get_timestamp, get_start_timestamp,
- timestamp_to_secs)
+ timestamp_to_secs, _get_timetuple)
EXAMPLE_TIME = time.mktime((2007, 9, 20, 16, 15, 14, 0, 0, -1))
@@ -17,6 +17,23 @@
class TestTime(unittest.TestCase):
+ def test_get_timetuple_excluding_millis(self):
+ assert_equal(_get_timetuple(12345)[:-1], time.localtime(12345)[:6])
+
+ def test_get_current_timetuple_excluding_millis(self):
+ while True:
+ expected = time.localtime()
+ actual = _get_timetuple()
+ if expected == time.localtime():
+ break
+ assert_equal(actual[:-1], expected[:6])
+
+ def test_get_timetuple_millis(self):
+ assert_equal(_get_timetuple(12345)[-2:], (45, 0))
+ assert_equal(_get_timetuple(12345.12345)[-2:], (45, 123))
+ assert_equal(_get_timetuple(12345.67890)[-2:], (45, 679))
+ assert_equal(_get_timetuple(12345.99999)[-2:], (46, 0))
+
def test_timestr_to_secs(self):
for inp, exp in [('1', 1),
('42', 42),
==============================================================================
Revision: 89569e438d9b
Author: Pekka Klärck
Date: Sat Jun 18 14:28:07 2011
Log: fixed secs_to_timestr when millis in given value round to seconds
http://code.google.com/p/robotframework/source/detail?r=89569e438d9b
Modified:
/src/robot/utils/robottime.py
/utest/utils/test_robottime.py
=======================================
--- /src/robot/utils/robottime.py Sat Jun 18 14:14:55 2011
+++ /src/robot/utils/robottime.py Sat Jun 18 14:28:07 2011
@@ -150,9 +150,7 @@
float_secs = abs(float_secs)
else:
sign = ''
- int_secs = int(float_secs)
- millis = (float_secs - int_secs) * 1000
- millis = int(round(millis))
+ int_secs, millis = _float_secs_to_secs_and_millis(float_secs)
secs = int_secs % 60
mins = int(int_secs / 60) % 60
hours = int(int_secs / (60*60)) % 24
=======================================
--- /utest/utils/test_robottime.py Sat Jun 18 14:14:55 2011
+++ /utest/utils/test_robottime.py Sat Jun 18 14:28:07 2011
@@ -80,7 +80,9 @@
for inp, compact, verbose in [
(0.001, '1ms', '1 millisecond'),
(0.002, '2ms', '2 milliseconds'),
+ (0.9999, '1s', '1 second'),
(1, '1s', '1 second'),
+ (1.9999, '2s', '2 seconds'),
(2, '2s', '2 seconds'),
(60, '1min', '1 minute'),
(120, '2min', '2 minutes'),
@@ -94,12 +96,14 @@
(7210.05, '2h 10s 50ms', '2 hours 10 seconds 50
milliseconds') ,
(11.1111111, '11s 111ms', '11 seconds 111 milliseconds'),
(0.55555555, '556ms', '556 milliseconds'),
- (0, '0s', '0 seconds') ,
+ (0, '0s', '0 seconds'),
+ (9999.9999, '2h 46min 40s', '2 hours 46 minutes 40 seconds'),
+ (10000, '2h 46min 40s', '2 hours 46 minutes 40 seconds'),
(-1, '- 1s', '- 1 second'),
(-171967.667, '- 1d 23h 46min 7s 667ms',
'- 1 day 23 hours 46 minutes 7 seconds 667 milliseconds')]:
- assert_equal(secs_to_timestr(inp), verbose)
- assert_equal(secs_to_timestr(inp, compact=True), compact)
+ assert_equal(secs_to_timestr(inp, compact=True), compact, inp)
+ assert_equal(secs_to_timestr(inp), verbose, inp)
def test_format_time(self):
timetuple = (2005, 11, 2, 14, 23, 12, 123)
==============================================================================
Revision: 32532ff33f86
Author: Pekka Klärck
Date: Sat Jun 18 14:43:00 2011
Log: Acceptance tests for Python library logging messages through
stdout with timestamps.
Update issue 456
Acceptance tests using Python done.
http://code.google.com/p/robotframework/source/detail?r=32532ff33f86
Added:
/atest/robot/test_libraries/timestamps_for_stdout_messages.txt
/atest/testdata/test_libraries/PythonLibUsingTimestamps.py
/atest/testdata/test_libraries/timestamps_for_stdout_messages.txt
=======================================
--- /dev/null
+++ /atest/robot/test_libraries/timestamps_for_stdout_messages.txt Sat Jun
18 14:43:00 2011
@@ -0,0 +1,30 @@
+*** Settings ***
+Suite Setup Run Tests ${EMPTY}
test_libraries/timestamps_for_stdout_messages.txt
+Force Tags regression pybot jybot
+Resource atest_resource.txt
+
+*** Test Cases ***
+
+Library adds timestamp as integer
+ ${tc} = Check Test Case ${TESTNAME}
+ Known timestamp should be correct ${tc.kws[0].msgs[0]}
+ Current timestamp should be smaller than kw end time ${tc.kws[0]}
+
+Library adds timestamp as float
+ ${tc} = Check Test Case ${TESTNAME}
+ Known timestamp should be correct ${tc.kws[0].msgs[0]}
+ Current timestamp should be smaller than kw end time ${tc.kws[0]}
+
+
+*** Keywords ***
+
+Known timestamp should be correct
+ [Arguments] ${msg}
+ Check log message ${msg} Known timestamp
+ Should Be Equal ${msg.timestamp} 20110618 20:43:54.931
+ Should Be Equal ${msg.time} 20:43:54.931
+
+Current timestamp should be smaller than kw end time
+ [Arguments] ${kw}
+ Check log message ${kw.msgs[1]} <b>Current</b> INFO html=True
+ Should Be True "${kw.endtime}" > "${kw.msgs[1].timestamp}"
=======================================
--- /dev/null
+++ /atest/testdata/test_libraries/PythonLibUsingTimestamps.py Sat Jun 18
14:43:00 2011
@@ -0,0 +1,12 @@
+import time
+
+
+def timestamp_as_integer():
+ print '*INFO:1308419034931* Known timestamp'
+ print '*HTML:%d* <b>Current</b>' % int(time.time() * 1000)
+ time.sleep(0.1)
+
+def timestamp_as_float():
+ print '*INFO:1308419034930.502342313* Known timestamp'
+ print '*HTML:%f* <b>Current</b>' % float(time.time() * 1000)
+ time.sleep(0.1)
=======================================
--- /dev/null
+++ /atest/testdata/test_libraries/timestamps_for_stdout_messages.txt Sat
Jun 18 14:43:00 2011
@@ -0,0 +1,14 @@
+*** Settings ***
+Library PythonLibUsingTimestamps.py
+#Library JavaLibUsingTimestamps
+
+
+*** Test Cases ***
+
+Library adds timestamp as integer
+ Timestamp as integer
+
+Library adds timestamp as float
+ Timestamp as float
+
+
==============================================================================
Revision: 9cab09c73806
Author: Pekka Klärck
Date: Sat Jun 18 15:00:50 2011
Log: Test adding timestamps to log messages via stdout also with Java
libs.
Update issue 456
Now also tested with Java libraries. Works as expected.
http://code.google.com/p/robotframework/source/detail?r=9cab09c73806
Added:
/atest/testdata/test_libraries/JavaLibUsingTimestamps.class
/atest/testdata/test_libraries/JavaLibUsingTimestamps.java
Modified:
/atest/robot/test_libraries/timestamps_for_stdout_messages.txt
/atest/testdata/test_libraries/timestamps_for_stdout_messages.txt
=======================================
--- /dev/null
+++ /atest/testdata/test_libraries/JavaLibUsingTimestamps.class Sat Jun 18
15:00:50 2011
@@ -0,0 +1,21 @@
+Êþº¾ 1 =
+
+
+
+
+ !
+ "
+ #
+
+ $
+ % &
+ ' d
+ ( ) * + <init> ()V Code LineNumberTable
+javaTimestamp
+Exceptions ,
+SourceFile JavaLibUsingTimestamps.java - . / $*INFO:1308419034931*
Known
timestamp 0 1 2 java/lang/StringBuilder *HTML: 3 4 5 6 3 7 *<b>Current</b> 8 9 : ; < JavaLibUsingTimestamps java/lang/Object
+java/lang/InterruptedException java/lang/System out Ljava/io/PrintStream; java/io/PrintStream println (Ljava/lang/String;)V append -(Ljava/lang/String;)Ljava/lang/StringBuilder; currentTimeMillis ()J
+(J)Ljava/lang/StringBuilder; toString ()Ljava/lang/String; java/lang/Thread sleep (J)V !
+ *· ± S /² ¶ ² » Y· ¶ ¸
¶
+¶ ¶ ¶
+¸ ± ( .
=======================================
--- /dev/null
+++ /atest/testdata/test_libraries/JavaLibUsingTimestamps.java Sat Jun 18
15:00:50 2011
@@ -0,0 +1,10 @@
+public class JavaLibUsingTimestamps {
+
+ public void javaTimestamp() throws InterruptedException {
+ System.out.println("*INFO:1308419034931* Known timestamp");
+ System.out.println("*HTML:" +
+ System.currentTimeMillis() +
+ "*<b>Current</b>");
+ Thread.sleep(100);
+ }
+}
=======================================
--- /atest/robot/test_libraries/timestamps_for_stdout_messages.txt Sat Jun
18 14:43:00 2011
+++ /atest/robot/test_libraries/timestamps_for_stdout_messages.txt Sat Jun
18 15:00:50 2011
@@ -1,22 +1,28 @@
*** Settings ***
Suite Setup Run Tests ${EMPTY}
test_libraries/timestamps_for_stdout_messages.txt
-Force Tags regression pybot jybot
+Force Tags regression
+Default Tags pybot jybot
Resource atest_resource.txt
*** Test Cases ***
Library adds timestamp as integer
- ${tc} = Check Test Case ${TESTNAME}
- Known timestamp should be correct ${tc.kws[0].msgs[0]}
- Current timestamp should be smaller than kw end time ${tc.kws[0]}
+ Test's timestamps should be correct
Library adds timestamp as float
- ${tc} = Check Test Case ${TESTNAME}
- Known timestamp should be correct ${tc.kws[0].msgs[0]}
- Current timestamp should be smaller than kw end time ${tc.kws[0]}
+ Test's timestamps should be correct
+
+Java library adds timestamp
+ [Tags] jybot
+ Test's timestamps should be correct
*** Keywords ***
+
+Test's timestamps should be correct
+ ${tc} = Check Test Case ${TESTNAME}
+ Known timestamp should be correct ${tc.kws[0].msgs[0]}
+ Current timestamp should be smaller than kw end time ${tc.kws[0]}
Known timestamp should be correct
[Arguments] ${msg}
=======================================
--- /atest/testdata/test_libraries/timestamps_for_stdout_messages.txt Sat
Jun 18 14:43:00 2011
+++ /atest/testdata/test_libraries/timestamps_for_stdout_messages.txt Sat
Jun 18 15:00:50 2011
@@ -1,6 +1,6 @@
*** Settings ***
Library PythonLibUsingTimestamps.py
-#Library JavaLibUsingTimestamps
+Library JavaLibUsingTimestamps.java
*** Test Cases ***
@@ -11,4 +11,5 @@
Library adds timestamp as float
Timestamp as float
-
+Java library adds timestamp
+ Java timestamp