pybind11/example/example-python-types.ref

147 lines
4.2 KiB
Plaintext
Raw Normal View History

15
5
example.ExamplePythonTypes: No constructor defined!
can't set attribute
Improve constructor/destructor tracking This commit rewrites the examples that look for constructor/destructor calls to do so via static variable tracking rather than output parsing. The added ConstructorStats class provides methods to keep track of constructors and destructors, number of default/copy/move constructors, and number of copy/move assignments. It also provides a mechanism for storing values (e.g. for value construction), and then allows all of this to be checked at the end of a test by getting the statistics for a C++ (or python mapping) class. By not relying on the precise pattern of constructions/destructions, but rather simply ensuring that every construction is matched with a destruction on the same object, we ensure that everything that gets created also gets destroyed as expected. This replaces all of the various "std::cout << whatever" code in constructors/destructors with `print_created(this)`/`print_destroyed(this)`/etc. functions which provide similar output, but now has a unified format across the different examples, including a new ### prefix that makes mixed example output and lifecycle events easier to distinguish. With this change, relaxed mode is no longer needed, which enables testing for proper destruction under MSVC, and under any other compiler that generates code calling extra constructors, or optimizes away any constructors. GCC/clang are used as the baseline for move constructors; the tests are adapted to allow more move constructors to be evoked (but other types are constructors much have matching counts). This commit also disables output buffering of tests, as the buffering sometimes results in C++ output ending up in the middle of python output (or vice versa), depending on the OS/python version.
2016-08-07 17:05:26 +00:00
### ExamplePythonTypes @ 0x1045b80 created via new_instance
2015-11-30 11:30:28 +00:00
key: key2, value=value2
2015-10-01 14:48:34 +00:00
key: key, value=value
key: key, value=value
2015-07-05 18:05:44 +00:00
key: key2, value=value2
key: key3
2015-11-30 11:30:28 +00:00
key: key2
key: key1
key: key1
key: key2
key: key3
2015-07-05 18:05:44 +00:00
Entry at positon 0: value
list item 0: overwritten
list item 1: value2
list item 0: value
list item 1: value2
[u'array entry 1', u'array entry 2']
array item 0: array entry 1
array item 1: array entry 2
2015-07-05 18:05:44 +00:00
This exception was intentionally thrown.
(u'test', True)
(5L, u'test', True)
Help on class ExamplePythonTypes in module example
2015-07-05 18:05:44 +00:00
class EExxaammpplleePPyytthhoonnTTyyppeess(__builtin__.object)
2015-10-01 14:48:34 +00:00
| Example 2 documentation
|
2015-07-05 18:05:44 +00:00
| Methods defined here:
|
| ____iinniitt____(...)
| x.__init__(...) initializes x; see help(type(x)) for signature
|
| ggeett__aarrrraayy(...)
|
| Signature : (example.ExamplePythonTypes) -> List[unicode[2]]
| Return a C++ array
|
| ggeett__ddiicctt(...)
| Signature : (example.ExamplePythonTypes) -> dict
|
2015-07-05 18:05:44 +00:00
| Return a Python dictionary
|
| ggeett__ddiicctt__22(...)
|
| Signature : (example.ExamplePythonTypes) -> Dict[unicode, unicode]
2015-07-05 18:05:44 +00:00
| Return a C++ dictionary
|
| ggeett__lliisstt(...)
| Signature : (example.ExamplePythonTypes) -> list
|
2015-07-05 18:05:44 +00:00
| Return a Python list
|
| ggeett__lliisstt__22(...)
|
| Signature : (example.ExamplePythonTypes) -> List[unicode]
2015-07-05 18:05:44 +00:00
| Return a C++ list
|
| ggeett__sseett(...)
| Signature : (example.ExamplePythonTypes) -> set
|
| Return a Python set
|
| ggeett__sseett22(...)
| Signature : (example.ExamplePythonTypes) -> set
|
| Return a C++ set
|
| ppaaiirr__ppaasssstthhrroouugghh(...)
|
| Signature : (example.ExamplePythonTypes, Tuple[bool, unicode]) -> Tuple[unicode, bool]
2015-07-05 18:05:44 +00:00
| Return a pair in reversed order
|
| pprriinntt__aarrrraayy(...)
|
| Signature : (example.ExamplePythonTypes, List[unicode[2]]) -> None
| Print entries of a C++ array
|
| pprriinntt__ddiicctt(...)
|
| Signature : (example.ExamplePythonTypes, dict) -> None
2015-07-05 18:05:44 +00:00
| Print entries of a Python dictionary
|
| pprriinntt__ddiicctt__22(...)
|
| Signature : (example.ExamplePythonTypes, Dict[unicode, unicode]) -> None
2015-07-05 18:05:44 +00:00
| Print entries of a C++ dictionary
|
| pprriinntt__lliisstt(...)
|
| Signature : (example.ExamplePythonTypes, list) -> None
2015-07-05 18:05:44 +00:00
| Print entries of a Python list
|
| pprriinntt__lliisstt__22(...)
|
| Signature : (example.ExamplePythonTypes, List[unicode]) -> None
2015-07-05 18:05:44 +00:00
| Print entries of a C++ list
|
| pprriinntt__sseett(...)
|
| Signature : (example.ExamplePythonTypes, set) -> None
| Print entries of a Python set
|
| pprriinntt__sseett__22(...)
|
| Signature : (example.ExamplePythonTypes, Set[unicode]) -> None
| Print entries of a C++ set
|
| tthhrrooww__eexxcceeppttiioonn(...)
|
| Signature : (example.ExamplePythonTypes) -> None
2015-07-05 18:05:44 +00:00
| Throw an exception
|
| ttuuppllee__ppaasssstthhrroouugghh(...)
|
| Signature : (example.ExamplePythonTypes, Tuple[bool, unicode, int]) -> Tuple[int, unicode, bool]
2015-07-05 18:05:44 +00:00
| Return a triple in reversed order
|
2015-07-05 18:05:44 +00:00
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| ____nneeww____ = <built-in method __new__ of example.ExamplePythonTypes__Meta object>
| T.__new__(S, ...) -> a new object with type S, a subtype of T
|
| nneeww__iinnssttaannccee = <built-in method new_instance of PyCapsule object>
| Signature : () -> example.ExamplePythonTypes
|
| Return an instance
2015-07-05 18:05:44 +00:00
__name__(example) = example
__name__(example.ExamplePythonTypes) = ExamplePythonTypes
__module__(example.ExamplePythonTypes) = example
__name__(example.ExamplePythonTypes.get_set) = get_set
__module__(example.ExamplePythonTypes.get_set) = example
foo
bar
baz
boo
2016-08-13 23:05:05 +00:00
this is a str
this is a repr
Instances not destroyed: 1
### ExamplePythonTypes @ 0x1045b80 destroyed
Instances not destroyed: 0