def test_create_copy_with_context_copies_default_dimensions(): # arrange context = MetricsContext() context.set_default_dimensions({fake.word(): fake.word}) # act new_context = context.create_copy_with_context() # assert assert context.default_dimensions == new_context.default_dimensions assert context.default_dimensions is not new_context.default_dimensions
def test_set_dimensions_overwrites_all_dimensions(): # arrange context = MetricsContext() context.set_default_dimensions({fake.word(): fake.word}) context.put_dimensions({fake.word(): fake.word}) expected_dimensions = {fake.word(): fake.word} # act context.set_dimensions(expected_dimensions) # assert assert context.dimensions == expected_dimensions
def test_get_dimensions_returns_default_dimensions_if_custom_dimensions_not_set( ): # arrange context = MetricsContext() dimension_key = fake.word() dimension_value = fake.word() expected_dimensions = {dimension_key: dimension_value} context.set_default_dimensions(expected_dimensions) # act actual_dimensions = context.get_dimensions() # assert assert [expected_dimensions] == actual_dimensions
def test_create_copy_with_context_does_not_repeat_dimensions(): # arrange context = MetricsContext() expected_dimensions = {fake.word(): fake.word()} custom = {fake.word(): fake.word()} context.set_default_dimensions(expected_dimensions) context.put_dimensions(custom) new_context = context.create_copy_with_context() new_context.set_default_dimensions(expected_dimensions) new_context.put_dimensions(custom) # assert assert len(new_context.get_dimensions()) == 1
def test_get_dimensions_returns_merged_custom_and_default_dimensions(): # arrange context = MetricsContext() custom_dimension_key = fake.word() custom_dimension_value = fake.word() default_dimension_key = fake.word() default_dimension_value = fake.word() expected_dimensions = { default_dimension_key: default_dimension_value, custom_dimension_key: custom_dimension_value, } context.set_default_dimensions( {default_dimension_key: default_dimension_value}) context.put_dimensions({custom_dimension_key: custom_dimension_value}) # act actual_dimensions = context.get_dimensions() # assert assert [expected_dimensions] == actual_dimensions