Adding back a lost capability, but better this time. The user can now

specify a python module name where the class and functions will be
visible in python.  With care the user can mimic the C++ namespaces their
models reside in, but it isn't perfect nor automatic.  It's still pretty
neat.
This commit is contained in:
Alex Lin
2019-03-13 16:17:08 -05:00
parent be4372a831
commit 62948308b6
9 changed files with 242 additions and 9 deletions

View File

@ -0,0 +1,41 @@
from trick.unit_test import *
def main():
trick.stop(1.0)
trick_utest.unit_tests.enable()
trick_utest.unit_tests.set_file_name( os.getenv("TRICK_HOME") + "/trick_test/SIM_python_namespace.xml" )
trick_utest.unit_tests.set_test_name( "PythonNamespace" )
test_suite = "python_namespace"
# normal class methods from S_define
ball.foo_food.print_me()
ball.foo_inner_food.print_me()
ball.bar_food.print_me()
print
# new class from Foo.Food
food = trick.Foo.Food()
food.print_me()
TRICK_EXPECT_EQ( food.fast , 0, test_suite , "first level python namespace" )
food.fast = trick.Foo.Burger
TRICK_EXPECT_EQ( food.fast , 2, test_suite , "first level python namespace" )
# new class from Foo.Food.Inner
foodinner = trick.Foo.Inner.Food()
foodinner.print_me()
TRICK_EXPECT_EQ( foodinner.fast , 1, test_suite , "second level python namespace" )
foodinner.fast = trick.Foo.Inner.Burger
TRICK_EXPECT_EQ( foodinner.fast , 0, test_suite , "second level python namespace" )
# new class from Foo.Food.Inner
bar = trick.Bar.Food()
bar.print_me()
TRICK_EXPECT_EQ( bar.fast , 2, test_suite , "another first level python namespace" )
bar.fast = trick.Bar.Burger
TRICK_EXPECT_EQ( bar.fast , 1, test_suite , "another first level python namespace" )
if __name__ == "__main__":
main()