xref: /aosp_15_r20/external/pytorch/test/distributed/elastic/utils/logging_test.py (revision da0073e96a02ea20f0ac840b70461e3646d07c45)
1#!/usr/bin/env python3
2# Owner(s): ["oncall: r2p"]
3
4# Copyright (c) Facebook, Inc. and its affiliates.
5# All rights reserved.
6#
7# This source code is licensed under the BSD-style license found in the
8# LICENSE file in the root directory of this source tree.
9import torch.distributed.elastic.utils.logging as logging
10from torch.testing._internal.common_utils import run_tests, TestCase
11
12
13log = logging.get_logger()
14
15
16class LoggingTest(TestCase):
17    def setUp(self):
18        super().setUp()
19        self.clazz_log = logging.get_logger()
20
21    def test_logger_name(self):
22        local_log = logging.get_logger()
23        name_override_log = logging.get_logger("foobar")
24
25        self.assertEqual(__name__, log.name)
26        self.assertEqual(__name__, self.clazz_log.name)
27        self.assertEqual(__name__, local_log.name)
28        self.assertEqual("foobar", name_override_log.name)
29
30    def test_derive_module_name(self):
31        module_name = logging._derive_module_name(depth=1)
32        self.assertEqual(__name__, module_name)
33
34
35if __name__ == "__main__":
36    run_tests()
37