예제 #1
0
    def test_literal_invalid(self):
        """Test that an exception is raised if a Blackbird literal is invalid"""
        nonnumeric = blackbirdParser.NonnumericContext(parser, ctx)
        nonnumeric.getText = lambda: ""

        with pytest.raises(ValueError, match="Unknown value"):
            _literal(nonnumeric)
예제 #2
0
    def test_positional_string(self, parser, ctx):
        """Test a positional string is correctly extracted"""
        args = blackbirdParser.ArgumentsContext(parser, ctx)
        arg1 = blackbirdParser.ValContext(parser, ctx)

        nonnumeric = blackbirdParser.NonnumericContext(parser, ctx)
        nonnumeric.STR = lambda: True
        nonnumeric.getText = lambda: "Test value"

        arg1.nonnumeric = lambda: nonnumeric
        args.getChildren = lambda: [arg1]
        assert _get_arguments(args) == (["Test value"], {})
예제 #3
0
    def test_keyword_nonnumeric(self, parser, ctx):
        """Test a keyword nonnumeric is correctly extracted"""
        args = blackbirdParser.ArgumentsContext(parser, ctx)
        kwarg1 = blackbirdParser.KwargContext(parser, ctx)
        arg1 = blackbirdParser.ValContext(parser, ctx)
        name = blackbirdParser.NameContext(parser, ctx)
        nonnumeric = blackbirdParser.NonnumericContext(parser, ctx)

        nonnumeric.STR = lambda: True
        nonnumeric.getText = lambda: "Test value"

        name.getText = lambda: "test_kwarg"
        kwarg1.val = lambda: arg1
        kwarg1.NAME = lambda: name
        arg1.nonnumeric = lambda: nonnumeric
        args.getChildren = lambda: [kwarg1]
        assert _get_arguments(args) == ([], {"test_kwarg": "Test value"})
예제 #4
0
 def test_literal_string(self):
     """Test that a Blackbird string is properly converted to a Python type"""
     nonnumeric = blackbirdParser.NonnumericContext(parser, ctx)
     nonnumeric.STR = lambda: True
     nonnumeric.getText = lambda: "Test value"
     assert _literal(nonnumeric) == "Test value"
예제 #5
0
 def test_literal_bool_false(self):
     """Test that a Blackbird bool (False) is properly converted to a Python type"""
     nonnumeric = blackbirdParser.NonnumericContext(parser, ctx)
     nonnumeric.BOOL = lambda: True
     nonnumeric.getText = lambda: "False"
     assert not _literal(nonnumeric)