|
| 1 | +# Copyright 2018, OpenCensus Authors |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +import unittest |
| 16 | + |
| 17 | +from opencensus.tags import execution_context |
| 18 | +from opencensus.tags import tag_key as tag_key_module |
| 19 | +from opencensus.tags import tag_map as tag_map_module |
| 20 | +from opencensus.tags import tag_value as tag_value_module |
| 21 | + |
| 22 | + |
| 23 | +class TestTagExecutionContext(unittest.TestCase): |
| 24 | + |
| 25 | + def tearDown(self): |
| 26 | + execution_context.clear() |
| 27 | + |
| 28 | + def test_unset_tag_map(self): |
| 29 | + result = execution_context.get_current_tag_map() |
| 30 | + |
| 31 | + self.assertIsNone(result) |
| 32 | + |
| 33 | + def test_set_and_get_tag_map(self): |
| 34 | + key = tag_key_module.TagKey('key') |
| 35 | + value = tag_value_module.TagValue('value') |
| 36 | + tag_map = tag_map_module.TagMap() |
| 37 | + tag_map.insert(key, value) |
| 38 | + |
| 39 | + execution_context.set_current_tag_map(tag_map) |
| 40 | + |
| 41 | + result = execution_context.get_current_tag_map() |
| 42 | + |
| 43 | + self.assertEqual(result, tag_map) |
0 commit comments