File tree Expand file tree Collapse file tree
tests/test_core/test_utils Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import collections .abc
2+
3+ import pytest
4+
5+ from _plotly_utils .importers import relative_import
6+
7+
8+ def _make ():
9+ # Use the stdlib ``collections`` package as a stable lazy-import target.
10+ return relative_import (
11+ "collections" ,
12+ rel_modules = [".abc" ],
13+ rel_classes = [".abc.Mapping" ],
14+ )
15+
16+
17+ def test_all_lists_module_and_class_leaf_names ():
18+ all_ , _getattr , _dir = _make ()
19+ assert sorted (all_ ) == ["Mapping" , "abc" ]
20+
21+
22+ def test_getattr_lazily_imports_submodule ():
23+ _all , getattr_ , _dir = _make ()
24+ assert getattr_ ("abc" ) is collections .abc
25+
26+
27+ def test_getattr_lazily_imports_class ():
28+ _all , getattr_ , _dir = _make ()
29+ assert getattr_ ("Mapping" ) is collections .abc .Mapping
30+
31+
32+ def test_getattr_unknown_name_raises_attribute_error ():
33+ _all , getattr_ , _dir = _make ()
34+ with pytest .raises (AttributeError ):
35+ getattr_ ("does_not_exist" )
36+
37+
38+ def test_dir_returns_all ():
39+ all_ , _getattr , dir_ = _make ()
40+ assert sorted (dir_ ()) == sorted (all_ )
You can’t perform that action at this time.
0 commit comments