Skip to content

Commit

Permalink
tests for improved dir()
Browse files Browse the repository at this point in the history
  • Loading branch information
wlav committed Feb 10, 2022
1 parent 9bf3a2f commit f4446b3
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 2 deletions.
1 change: 1 addition & 0 deletions doc/source/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ master: 2.3.0
* Support for (multiple and nested) anonymous structs
* Pull forward upstream patch for PPC
* Only apply system_dirs patch (for asan) on Linux
* Add unloaded classes to namespaces in dir()


2021-11-14: 2.2.0
Expand Down
55 changes: 53 additions & 2 deletions test/test_fragile.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,59 @@ def test11_dir(self):

# TODO: think this through ... probably want this, but interferes with
# the (new) policy of lazy lookups
#assert 'fglobal' in members # function
#assert 'gI'in members # variable
#assert 'fglobal' in members # function
assert 'gI'in members # variable

# GetAllCppNames() behaves differently from python dir() but providing the full
# set, which is then filtered in dir(); check both
cppyy.cppdef("""\
#ifdef _MSC_VER
#define CPPYY_IMPORT extern __declspec(dllimport)
#else
#define CPPYY_IMPORT extern
#endif
namespace Cppyy {
typedef size_t TCppScope_t;
CPPYY_IMPORT TCppScope_t GetScope(const std::string& scope_name);
CPPYY_IMPORT void GetAllCppNames(TCppScope_t scope, std::set<std::string>& cppnames);
}""")

cppyy.cppdef("""\
namespace GG {
struct S {
int _a;
int _c;
S(int a, int c): _a{a}, _c{c} { }
S(): _a{0}, _c{0} { }
bool operator<(int i) { return i < (_a+_c); }
}; }""");


assert 'S' in dir(cppyy.gbl.GG)

handle = cppyy.gbl.Cppyy.GetScope("GG::S")
assert handle

cppnames = cppyy.gbl.std.set[str]()
cppyy.gbl.Cppyy.GetAllCppNames(handle, cppnames)

assert 'S' in cppnames
assert '_a' in cppnames
assert '_c' in cppnames

assert 'operator<' in cppnames

dirS = dir(cppyy.gbl.GG.S)

assert 'S' not in dirS # is __init__
assert '_a' in dirS
assert '_c' in dirS

assert 'operator<' not in dirS

def test12_imports(self):
"""Test ability to import from namespace (or fail with ImportError)"""
Expand Down

0 comments on commit f4446b3

Please sign in to comment.