How to use pynq - 10 common examples

To help you get started, we’ve selected a few pynq examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github heynemann / pynq / tests / unit / test_binary_arithmetic_expressions.py View on Github external
def test_nested_subtraction_expression(self):
        a = ConstantExpression(10)
        b = ConstantExpression(20)
        c = ConstantExpression(30)
        node_type = BinaryExpression.Subtract

        expr = BinaryExpression(node_type, BinaryExpression(node_type, a, b), c)

        self.assertEquals(expr.node_type, node_type)
        self.failUnless(isinstance(expr.lhs, BinaryExpression), "The left-hand side of the binary expression should be a binary expression as well, but is %s" % expr.lhs.__class__)
        self.assertEquals(expr.lhs.node_type, node_type)
        self.assertEquals(expr.lhs.lhs, a)
        self.assertEquals(expr.lhs.rhs, b)
        self.assertEquals(expr.rhs, c)
github heynemann / pynq / tests / unit / test_binary_arithmetic_expressions.py View on Github external
def test_expression_for_addition_of_two_constants(self):
        a = ConstantExpression(10)
        b = ConstantExpression(20)
        node_type = BinaryExpression.Add
        expr = BinaryExpression(node_type, a, b)

        self.assertEquals(expr.node_type, node_type)
        self.assertEquals(expr.lhs, a)
        self.assertEquals(expr.rhs, b)
github heynemann / pynq / tests / unit / test_unary_expressions.py View on Github external
def test_nested_negate_expression_representation(self):
        a = ConstantExpression(10)
        node_type = UnaryExpression.Negate

        expr = UnaryExpression(node_type, UnaryExpression(node_type, a))

        self.assertEquals("negate(negate(10))", str(expr))
github heynemann / pynq / tests / unit / test_binary_bitwise_expressions.py View on Github external
def test_expression_or_of_two_constants_representation(self):
        a = ConstantExpression(True)
        b = ConstantExpression(False)
        node_type = BinaryExpression.Or
        expr = BinaryExpression(node_type, a, b)
        
        self.assertEquals("(True or False)", str(expr))
github heynemann / pynq / tests / unit / test_unary_expressions.py View on Github external
def test_nested_negate_expression(self):
        a = ConstantExpression(10)
        node_type = UnaryExpression.Negate

        expr = UnaryExpression(node_type, UnaryExpression(node_type, a))

        self.assertEquals(expr.node_type, node_type)
        self.failUnless(isinstance(expr.rhs, UnaryExpression), "The right-hand side of the unary expression should be an unary expression as well, but is %s" % expr.rhs.__class__)
        self.assertEquals(expr.rhs.node_type, node_type)
        self.assertEquals(expr.rhs.rhs, a)
github heynemann / pynq / tests / unit / test_binary_bitwise_expressions.py View on Github external
def test_nested_or_expression_representation(self):
        a = ConstantExpression(True)
        b = ConstantExpression(False)
        c = ConstantExpression(None)
        node_type = BinaryExpression.Or

        expr = BinaryExpression(node_type, BinaryExpression(node_type, a, b), c)

        self.assertEquals("((True or False) or None)", str(expr))
github heynemann / pynq / tests / unit / test_binary_arithmetic_expressions.py View on Github external
def test_nested_division_expression(self):
        a = ConstantExpression(10)
        b = ConstantExpression(20)
        c = ConstantExpression(30)
        node_type = BinaryExpression.Divide

        expr = BinaryExpression(node_type, BinaryExpression(node_type, a, b), c)

        self.assertEquals(expr.node_type, node_type)
        self.failUnless(isinstance(expr.lhs, BinaryExpression), "The left-hand side of the binary expression should be a binary expression as well, but is %s" % expr.lhs.__class__)
        self.assertEquals(expr.lhs.node_type, node_type)
        self.assertEquals(expr.lhs.lhs, a)
        self.assertEquals(expr.lhs.rhs, b)
        self.assertEquals(expr.rhs, c)
github heynemann / pynq / tests / unit / test_binary_arithmetic_expressions.py View on Github external
def test_binary_expression_only_accepts_expressions_for_arguments(self):
        a = 10
        a_expr = ConstantExpression(10)
        b = "20"
        b_expr = ConstantExpression(20)
        node_type = BinaryExpression.Add

        self.assertRaisesEx(ValueError, BinaryExpression, node_type, a, b_expr, exc_pattern=re.compile("Lhs must be an expression \(an instance of a class that inherits from pynq.Expression\)"))
        self.assertRaisesEx(ValueError, BinaryExpression, node_type, a_expr, b, exc_pattern=re.compile("Rhs must be an expression \(an instance of a class that inherits from pynq.Expression\)"))
        self.assertRaisesEx(ValueError, BinaryExpression, None, a_expr, b_expr, exc_pattern=re.compile("The BinaryExpression node type is required"))
github heynemann / pynq / tests / unit / test_binary_arithmetic_expressions.py View on Github external
def test_expression_for_division_of_two_constants(self):
        a = ConstantExpression(10)
        b = ConstantExpression(20)
        node_type = BinaryExpression.Divide
        expr = BinaryExpression(node_type, a, b)

        self.assertEquals(expr.node_type, node_type)
        self.assertEquals(expr.lhs, a)
        self.assertEquals(expr.rhs, b)
github heynemann / pynq / tests / unit / test_binary_arithmetic_expressions.py View on Github external
def test_nested_subtraction_expression(self):
        a = ConstantExpression(10)
        b = ConstantExpression(20)
        c = ConstantExpression(30)
        node_type = BinaryExpression.Subtract

        expr = BinaryExpression(node_type, BinaryExpression(node_type, a, b), c)

        self.assertEquals(expr.node_type, node_type)
        self.failUnless(isinstance(expr.lhs, BinaryExpression), "The left-hand side of the binary expression should be a binary expression as well, but is %s" % expr.lhs.__class__)
        self.assertEquals(expr.lhs.node_type, node_type)
        self.assertEquals(expr.lhs.lhs, a)
        self.assertEquals(expr.lhs.rhs, b)
        self.assertEquals(expr.rhs, c)