File tree Expand file tree Collapse file tree 1 file changed +19
-1
lines changed
zulip_bots/zulip_bots/tests Expand file tree Collapse file tree 1 file changed +19
-1
lines changed Original file line number Diff line number Diff line change 1+ import pytest
12from pathlib import Path
23from unittest import TestCase
3-
4+ from unittest . mock import patch
45from zulip_bots import finder
56
67
@@ -12,3 +13,20 @@ def test_resolve_bot_path(self) -> None:
1213 expected_bot_path_and_name = (expected_bot_path , expected_bot_name )
1314 actual_bot_path_and_name = finder .resolve_bot_path ("helloworld" )
1415 self .assertEqual (expected_bot_path_and_name , actual_bot_path_and_name )
16+
17+
18+ def test_import_metadata_standard (self ) -> None :
19+ # Simulate Python 3.10 or above by mocking importlib.metadata
20+ with patch ("importlib.metadata.metadata" , return_value = "mocked_metadata" ) as mock_metadata :
21+ try :
22+ from importlib .metadata import metadata
23+ result = "Using standard library importlib.metadata"
24+ except ImportError :
25+ from importlib_metadata import metadata
26+ result = "Using external importlib_metadata"
27+
28+ # Assert that the correct import was chosen
29+ self .assertEqual (result , "Using standard library importlib.metadata" )
30+ self .assertEqual (metadata ("some_package" ), "mocked_metadata" )
31+ mock_metadata .assert_called_once_with ("some_package" )
32+
You can’t perform that action at this time.
0 commit comments