public void PythonInterop_Operators_Fallback1() {
if (!_driver.RunPython) return;
var py = Runtime.GetEngine("python");
ScriptScope scope = py.CreateScope();
scope.SetVariable("ClassWithOperators", typeof(ClassWithOperators1));
py.Execute(@"
import clr
class C(clr.GetPythonType(ClassWithOperators)): pass
", scope);
XAssertOutput(() =>
Engine.Execute(@"
BinaryOperators = [:+, :-, :/, :*, :%, :==, :>, :>=, :<, :<=, :&, :|, :^, :<<, :>>, :**]
UnaryOperators = [:-@, :+@, :~]
Operators = BinaryOperators + UnaryOperators
class_with_operators.to_class.module_eval do
Operators.each do |op|
define_method(op) do
Kernel.print op, ' '
end
end
end
c = C().new
p(c + c)
p(c - c)
p(c / c)
p(c * c)
p(c % c)
p(c == c)
p(c > c)
p(c >= c)
p(c < c)
p(c <= c)
p(c & c)
p(c | c)
p(c ^ c)
p(c << 1)
p(c >> 1)
p(c ** c)
p(-c)
p(+c)
p(~c)
", scope), @"
");
}