33import pytest
44from google_cloud_logger import GoogleCloudFormatter
55
6+
67# from https://stackoverflow.com/a/19258720
78class FakeCode (object ):
89 def __init__ (self , co_filename , co_name ):
@@ -64,7 +65,9 @@ def record_with_extra_attribute(log_record_factory, mocker):
6465 "lineno" : "88" ,
6566 "levelname" : "WARNING" ,
6667 "message" : "farofa" ,
67- "extra" : {"extra_field" : "extra" },
68+ "extra" : {
69+ "extra_field" : "extra"
70+ },
6871 }
6972 record = log_record_factory (** data )
7073 record .getMessage = mocker .Mock (return_value = data ["message" ])
@@ -95,19 +98,25 @@ def test_add_fields(formatter, record, mocker):
9598 mocker .patch .object (
9699 formatter ,
97100 "make_entry" ,
98- return_value = OrderedDict (
99- [
100- ("timestamp" , "2018-08-30 20:40:57Z" ),
101- ("severity" , "WARNING" ),
102- ("message" , "farofa" ),
103- ("labels" , {"type" : "python-application" }),
104- ("metadata" , {"userLabels" : {}}),
105- (
106- "sourceLocation" ,
107- {"file" : "_internal.py" , "function" : "_log" , "line" : "88" },
108- ),
109- ]
110- ),
101+ return_value = OrderedDict ([
102+ ("timestamp" , "2018-08-30 20:40:57Z" ),
103+ ("severity" , "WARNING" ),
104+ ("message" , "farofa" ),
105+ ("labels" , {
106+ "type" : "python-application"
107+ }),
108+ ("metadata" , {
109+ "userLabels" : {}
110+ }),
111+ (
112+ "sourceLocation" ,
113+ {
114+ "file" : "_internal.py" ,
115+ "function" : "_log" ,
116+ "line" : "88"
117+ },
118+ ),
119+ ]),
111120 )
112121 formatter .add_fields (log_record , record , {})
113122
@@ -141,7 +150,8 @@ def test_make_metadata(formatter, record):
141150 assert metadata ["userLabels" ]["extra_field" ] == "extra"
142151
143152
144- def test_make_metadata_with_extra_attribute (formatter , record_with_extra_attribute ):
153+ def test_make_metadata_with_extra_attribute (formatter ,
154+ record_with_extra_attribute ):
145155 metadata = formatter .make_metadata (record_with_extra_attribute )
146156
147157 assert metadata ["userLabels" ]["extra_field" ] == "extra"
@@ -166,10 +176,8 @@ def test_make_source_location(formatter, record):
166176
167177
168178def test_format_timestamp (formatter ):
169- assert (
170- formatter .format_timestamp ("2018-08-30 20:40:57,245" )
171- == "2018-08-30T20:40:57.245000Z"
172- )
179+ assert (formatter .format_timestamp ("2018-08-30 20:40:57,245" ) ==
180+ "2018-08-30T20:40:57.245000Z" )
173181
174182
175183@pytest .mark .parametrize (
0 commit comments