Commits

Boris FELD committed 00f3dd4

Pass Status object to CloseRecord instead of its human representation.

It breaks reemission.

Comments (0)

Files changed (11)

goatlog/__init__.py

 
         args = list(args)
         # Arg 0 is context id
-        args.insert(1, status.human)
+        args.insert(1, status)
 
         close_record_class = self.registry.close_ctx_cls['context.' + record_type]
         self.handle(close_record_class(*args, **kwargs))

goatlog/records.py

 
         # Rename the date dump field to stop date
         del parent_data["date"]
-        parent_data.update({"stop-date": self.created, "status": self.status})
+        parent_data.update({"stop-date": self.created,
+            "status": self.status.human})
 
         return parent_data
 
         self.msg = self.getMessage()
 
     def getMessage(self):
-        data = (id(self.step), self.status)
+        data = (id(self.step), self.status.human)
         return 'Step <%s> completed with status %s' % data
 
     def _dump(self):
 
     def getMessage(self):
         return 'File context <%s> completed with status %s' % (self.filepath,
-            self.status)
+            self.status.human)
 
     def _dump(self):
         parent_data = ContextCloseRecord._dump(self)
 
     def getMessage(self):
         return 'Line context #%s completed with status %s' % (self.line,
-            self.status)
+            self.status.human)
 
     def _dump(self):
         parent_data = ContextCloseRecord._dump(self)

tests/scenario/test_context_close_dump.json

     "contents":[
         {
             "stop-date":2,
-            "status":"status",
+            "status":"Good",
             "start-date":1,
             "data_name":"data_value",
             "type":"context",
             "contents":[]
         }
     ]
-}
+}

tests/scenario/test_context_close_dump.py

 Test that additionnal dump data in close context are correctly merged into context record.
 '''
 
-from goatlog import LogManager
+from goatlog import LogManager, STATUSES
 from goatlog.records import ContextCloseRecord, ContextOpenRecord
 
 manager = LogManager("logger", handlers=[TEST_HANDLER])
 ContextCloseRecord._dump = _dump
 
 manager.handle(ContextOpenRecord(context_id))
-manager.handle(ContextCloseRecord(context_id, 'status'))
+manager.handle(ContextCloseRecord(context_id, STATUSES.DEFAULT))
 
 ContextCloseRecord._dump = original

tests/scenario/test_in_context_message.json

     "contents":[
         {
             "stop-date":3,
-            "status":"status",
+            "status":"Good",
             "start-date":1,
             "type":"context",
             "id":"context_id",
             ]
         }
     ]
-}
+}

tests/scenario/test_in_context_message.py

-from goatlog import LogManager
+from goatlog import LogManager, STATUSES
 from goatlog.records import ContextOpenRecord, ContextCloseRecord
 
 manager = LogManager("logger", handlers=[TEST_HANDLER])
 
 manager.handle(ContextOpenRecord(context_id))
 manager.info(message)
-manager.handle(ContextCloseRecord(context_id, 'status'))
+manager.handle(ContextCloseRecord(context_id, STATUSES.DEFAULT))

tests/scenario/test_simple_context.json

     "contents":[
         {
             "stop-date":2,
-            "status":"status",
+            "status":"Good",
             "start-date":1,
             "type":"context",
             "id":"context_id",

tests/scenario/test_simple_context.py

-from goatlog import LogManager
+from goatlog import LogManager, STATUSES
 from goatlog.records import ContextOpenRecord, ContextCloseRecord
 
 manager = LogManager("logger", handlers=[TEST_HANDLER])
 context_id = "context_id"
 
 manager.handle(ContextOpenRecord(context_id))
-manager.handle(ContextCloseRecord(context_id, 'status'))
+manager.handle(ContextCloseRecord(context_id, STATUSES.DEFAULT))

tests/test_handlers.py

 from StringIO import StringIO
 from os.path import splitext
 
+from goatlog import STATUSES
 from goatlog.records import ContextOpenRecord, ContextCloseRecord, Log
 from goatlog.handlers import BaseRichHandler, JsonHandler
 
         self.assertEqual(mock_open.call_args_list, [Call(open_context)])
 
     def test_dispatch_close_context(self):
-        close_context = ContextCloseRecord('test', 'status')
+        close_context = ContextCloseRecord('test', STATUSES.DEFAULT)
 
         with patch.object(self.handler, '_close_context') as mock_close:
             self.handler.emit(close_context)

tests/test_log.py

         with LogCapture() as captured_logs:
             self.log.handle(ContextOpenRecord(context_id))
             self.log.info(message)
-            self.log.handle(ContextCloseRecord(context_id, 'status'))
+            self.log.handle(ContextCloseRecord(context_id, STATUSES.DEFAULT))
 
         self.assertEqual(captured_logs.actual(),
             [
             self.log.info(message1)
             self.log.handle(ContextOpenRecord(context_id2))
             self.log.info(message2)
-            self.log.handle(ContextCloseRecord(context_id2, 'status'))
+            self.log.handle(ContextCloseRecord(context_id2, STATUSES.DEFAULT))
             self.log.info(message3)
-            self.log.handle(ContextCloseRecord(context_id1, 'status'))
+            self.log.handle(ContextCloseRecord(context_id1, STATUSES.DEFAULT))
 
         self.assertEqual(captured_logs.actual(),
             [
 
         self.log.handle(ropen(context_id))
         self.assertRaises(MismatchCloseContext, self.log.handle,
-                          rclose(context_id, 'status'))
+                          rclose(context_id, STATUSES.DEFAULT))
 
 
 class LogManagerTestCase(unittest.TestCase):
         open_record = mock_open_record()
         registry = RecordRegistry([open_record, close_record])
 
+        status = STATUSES.DEFAULT
+
         args = ['foo', 'bar']
-        kwargs = {'kwarg': 'kwvalue'}
+        kwargs = {'kwarg': 'kwvalue', 'status': status}
         log_manager = LogManager('logger_id', registry=registry)
         log_manager.open('fake')
         log_manager.close('fake', *args, **kwargs)
 
-        # Close automatically add a status args with 'Good' as default value
-        args.insert(1, 'Good')
+        args.insert(1, status)
+        kwargs.pop('status')
+
         self.assertEqual(close_record.args, tuple(args))
         self.assertEqual(close_record.kwargs, kwargs)
 
         args = ['foo', 'bar']
         kwargs = {'kwarg': 'kwvalue'}
 
+        status = STATUSES.ERROR
         close_args = ['babar']
-        close_kwargs = {'close': 'closed', 'status': STATUSES.ERROR}
+        close_kwargs = {'close': 'closed', 'status': status}
 
         log_manager = LogManager('logger_id', registry=registry)
         with log_manager.context('fake', *args, **kwargs) as ctx:
         self.assertEqual(open_record.kwargs, kwargs)
 
         # Check close record args
-        args.insert(1, STATUSES.ERROR.human)
+        args.insert(1, status)
         args.extend(close_args)
 
         del close_kwargs['status']
 # -*- coding: utf-8 -*-
 
 import logging
+from goatlog import STATUSES
 
 
 """
         kwargs = {}
 
         def __init__(self, *args, **kwargs):
-            ContextCloseRecord.__init__(self, 'fake', 'status')
+            ContextCloseRecord.__init__(self, 'fake', STATUSES.DEFAULT)
             MockCloseRecord.args = args
             MockCloseRecord.kwargs = kwargs
     return MockCloseRecord