<s> from hamcrest import assert_that , has_entries <EOL> import os <EOL> import logging <EOL> import json <EOL> from performanceplatform . collector . logging_setup import ( <EOL> set_up_logging , <EOL> extra_fields_from_exception ) <EOL> import unittest <EOL> class TestJsonLogging ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . logger = logging . getLogger ( ) <EOL> def test_json_log_written_when_logger_called ( self ) : <EOL> set_up_logging ( '<STR_LIT>' , logging . DEBUG , '<STR_LIT>' , None ) <EOL> logging . info ( '<STR_LIT>' ) <EOL> with open ( '<STR_LIT>' ) as log_file : <EOL> data = json . loads ( log_file . readlines ( ) [ - <NUM_LIT:1> ] ) <EOL> assert_that ( data , has_entries ( { <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } ) ) <EOL> assert_that ( data , has_entries ( { <EOL> '<STR_LIT>' : [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> } ) ) <EOL> os . remove ( '<STR_LIT>' ) <EOL> os . remove ( '<STR_LIT>' ) <EOL> def test_extra_fields_from_exception ( self ) : <EOL> try : <EOL> raise Exception ( '<STR_LIT:test>' ) <EOL> except Exception as e : <EOL> assert_that ( extra_fields_from_exception ( e ) , has_entries ( { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:test>' <EOL> } ) ) </s>
