Commit 27b53e04 authored by Eric Cousineau's avatar Eric Cousineau
Browse files

Add build/test example in README, minor Python updates

- autopybind11.py: Ensure root-level imperative code is inside main()
- Stop using deprecated unittest.TestCase.assertEquals
parent a87a911e
......@@ -48,7 +48,25 @@ PIP program to install all required Python Libraries. Execute::
pip install -r requirements.txt
to install the other required programs.
to install the other required programs. (It is recommend to use this through a
virtual enviroment!)
Running Tests
#############
Here's a small recipe for setting up local dependencies and building and
running the tests:
.. code-block:: shell
# In project root
python3 -m virtualenv -p python3 ./venv/
source ./venv/bin/activate
pip install -r requirements.txt
mkdir build && cd build
cmake ..
make -j
ctest -V -R
Preparing C++ code
------------------
......
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt
from configargparse import ArgParser, YAMLConfigFileParser
from op_names import names_dict, arg_dependent_ops
from bindings_sorter import get_binding_order
import text_blocks as tb
import copy
import fileinput
import glob
import yaml
import logging
import os
import posixpath
from configargparse import ArgParser, YAMLConfigFileParser
import pygccxml
import pygccxml.declarations as dec
import yaml
from bindings_sorter import get_binding_order
from op_names import names_dict, arg_dependent_ops
import text_blocks as tb
class BindingsGenerator:
......@@ -689,41 +690,46 @@ class BindingsGenerator:
self.generate_bindings(yaml.load(open(self.opts.yaml_path, "r")), self.name_data)
arg = ArgParser(config_file_parser_class=YAMLConfigFileParser)
arg.add("-o", "--output", action="store", dest="output_dir", required=False, default=os.getcwd())
arg.add("-y", "--input_yaml", action="store", dest="yaml_path",
help="Path to input YAML file of objects to process", required=True)
arg.add("--module_name", action="store", dest="module_name",
help="Desired name of the output PyBind11 module", required=True)
arg.add("-g", "--castxml-path", action="store", dest="castxml_path",
help="Path to castxml", required=False)
arg.add("-cg", "--config-path", dest="config_dir", required=False, is_config_file=True, help="config file path")
arg.add("--no-generation", "-n", help="Only print name of files to be generated",
dest="no_generation", action="store_true", required=False)
arg.add("-rs", "--input_response", required=False, dest='rsp_path', default='')
arg.add("-pm", "--private_members", required=False, action='store_true', dest='pm_flag', default=False)
# The formatted strings that will write the pybind code are also configurable
arg.add("--common_cpp_body_fmt", required=False, default=tb.common_cpp_body)
arg.add("--class_info_body_fmt", required=False, default=tb.class_info_body)
arg.add("--init_fun_signature_fmt", required=False, default=tb.init_fun_signature)
arg.add("--init_fun_forward_fmt", required=False, default=tb.init_fun_forward)
arg.add("--cppbody_fmt", type=str, required=False, default=tb.cppbody)
arg.add("--module_cpp_fmt", required=False, default=tb.module_cpp)
arg.add("--member_func_fmt", required=False, default=tb.member_func)
arg.add("--constructor_fmt", required=False, default=tb.constructor)
arg.add("--member_func_arg_fmt", required=False, default=tb.member_func_arg)
arg.add("--public_member_var_fmt", required=False, default=tb.public_member_var)
arg.add("--private_member_var_fmt", required=False, default=tb.private_member_var)
arg.add("--member_reference_fmt", required=False, default=tb.member_reference)
arg.add("--overload_template_fmt", required=False, default=tb.overload_template)
arg.add("--wrap_header_fmt", required=False, default=tb.wrap_header)
arg.add("--operator_fmt", required=False, default=tb.operator_template)
arg.add("--call_operator_fmt", required=False, default=tb.call_template)
arg.add("--enum_header_fmt", required=False, default=tb.enum_header)
arg.add("--enum_val_fmt", required=False, default=tb.enum_val)
options = arg.parse_args()
BindingsGenerator(options).parse_and_generate()
def main():
arg = ArgParser(config_file_parser_class=YAMLConfigFileParser)
arg.add("-o", "--output", action="store", dest="output_dir", required=False, default=os.getcwd())
arg.add("-y", "--input_yaml", action="store", dest="yaml_path",
help="Path to input YAML file of objects to process", required=True)
arg.add("--module_name", action="store", dest="module_name",
help="Desired name of the output PyBind11 module", required=True)
arg.add("-g", "--castxml-path", action="store", dest="castxml_path",
help="Path to castxml", required=False)
arg.add("-cg", "--config-path", dest="config_dir", required=False, is_config_file=True, help="config file path")
arg.add("--no-generation", "-n", help="Only print name of files to be generated",
dest="no_generation", action="store_true", required=False)
arg.add("-rs", "--input_response", required=False, dest='rsp_path', default='')
arg.add("-pm", "--private_members", required=False, action='store_true', dest='pm_flag', default=False)
# The formatted strings that will write the pybind code are also configurable
arg.add("--common_cpp_body_fmt", required=False, default=tb.common_cpp_body)
arg.add("--class_info_body_fmt", required=False, default=tb.class_info_body)
arg.add("--init_fun_signature_fmt", required=False, default=tb.init_fun_signature)
arg.add("--init_fun_forward_fmt", required=False, default=tb.init_fun_forward)
arg.add("--cppbody_fmt", type=str, required=False, default=tb.cppbody)
arg.add("--module_cpp_fmt", required=False, default=tb.module_cpp)
arg.add("--member_func_fmt", required=False, default=tb.member_func)
arg.add("--constructor_fmt", required=False, default=tb.constructor)
arg.add("--member_func_arg_fmt", required=False, default=tb.member_func_arg)
arg.add("--public_member_var_fmt", required=False, default=tb.public_member_var)
arg.add("--private_member_var_fmt", required=False, default=tb.private_member_var)
arg.add("--member_reference_fmt", required=False, default=tb.member_reference)
arg.add("--overload_template_fmt", required=False, default=tb.overload_template)
arg.add("--wrap_header_fmt", required=False, default=tb.wrap_header)
arg.add("--operator_fmt", required=False, default=tb.operator_template)
arg.add("--call_operator_fmt", required=False, default=tb.call_template)
arg.add("--enum_header_fmt", required=False, default=tb.enum_header)
arg.add("--enum_val_fmt", required=False, default=tb.enum_val)
options = arg.parse_args()
BindingsGenerator(options).parse_and_generate()
if __name__ == "__main__":
main()
......@@ -21,8 +21,8 @@ class inheritanceTests(unittest.TestCase):
im.Base_py()
def test_overrides(self):
self.assertEquals(im.Derived1_py().foo(), "Called from Derived1")
self.assertEquals(im.Derived2_py().foo(), "Called from Derived2")
self.assertEqual(im.Derived1_py().foo(), "Called from Derived1")
self.assertEqual(im.Derived2_py().foo(), "Called from Derived2")
def test_inheritance(self):
assert isinstance(im.Derived2_py(), im.Derived1_py)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment