@@ -54,6 +54,77 @@ def test_put_dimension_adds_to_dimensions():
54
54
assert context .dimensions == [dimension_set ]
55
55
56
56
57
+ def test_put_dimensions_accept_multiple_unique_dimensions ():
58
+ # arrange
59
+ context = MetricsContext ()
60
+ dimension1 = {fake .word (): fake .word ()}
61
+ dimension2 = {fake .word (): fake .word ()}
62
+
63
+ # act
64
+ context .put_dimensions (dimension1 )
65
+ context .put_dimensions (dimension2 )
66
+
67
+ # assert
68
+ assert len (context .get_dimensions ()) == 2
69
+ assert context .get_dimensions ()[0 ] == dimension1
70
+ assert context .get_dimensions ()[1 ] == dimension2
71
+
72
+
73
+ def test_put_dimension_prevent_duplicate_dimensions ():
74
+ # arrange
75
+ context = MetricsContext ()
76
+ pair1 = [fake .word (), fake .word ()]
77
+ pair2 = [fake .word (), fake .word ()]
78
+
79
+ dimension1 = {pair1 [0 ]: pair1 [1 ]}
80
+ dimension2 = {pair2 [0 ]: pair2 [1 ]}
81
+ dimension3 = {pair1 [0 ]: pair1 [1 ], pair2 [0 ]: pair2 [1 ]}
82
+
83
+ # act
84
+ context .put_dimensions (dimension1 )
85
+ context .put_dimensions (dimension2 )
86
+ context .put_dimensions (dimension1 )
87
+ context .put_dimensions (dimension3 )
88
+ context .put_dimensions (dimension2 )
89
+ context .put_dimensions (dimension3 )
90
+
91
+ # assert
92
+ assert len (context .get_dimensions ()) == 3
93
+ assert context .get_dimensions ()[0 ] == dimension1
94
+ assert context .get_dimensions ()[1 ] == dimension2
95
+ assert context .get_dimensions ()[2 ] == dimension3
96
+
97
+
98
+ def test_put_dimension_sort_duplicate_dimensions ():
99
+ # arrange
100
+ context = MetricsContext ()
101
+ key1 = fake .word ()
102
+ key2 = fake .word ()
103
+ val1 = fake .word ()
104
+ val2 = fake .word ()
105
+
106
+ dimension1 = {key1 : val1 }
107
+ dimension2 = {key2 : val2 }
108
+ dimension3 = {key1 : val2 }
109
+ dimension4 = {key2 : val1 }
110
+ dimension5 = {key1 : val1 , key2 : val2 }
111
+ dimension6 = {key1 : val2 , key2 : val1 }
112
+
113
+ # act
114
+ context .put_dimensions (dimension1 )
115
+ context .put_dimensions (dimension2 )
116
+ context .put_dimensions (dimension5 )
117
+ context .put_dimensions (dimension3 )
118
+ context .put_dimensions (dimension4 )
119
+ context .put_dimensions (dimension6 )
120
+
121
+ # assert
122
+ assert len (context .get_dimensions ()) == 3
123
+ assert context .get_dimensions ()[0 ] == dimension3
124
+ assert context .get_dimensions ()[1 ] == dimension4
125
+ assert context .get_dimensions ()[2 ] == dimension6
126
+
127
+
57
128
def test_get_dimensions_returns_only_custom_dimensions_if_no_default_dimensions_not_set ():
58
129
# arrange
59
130
context = MetricsContext ()
0 commit comments