def visitTerminal(self, node): if node.symbol.type == STIXPatternParser.IntLiteral: return stix2.IntegerConstant(node.getText()) elif node.symbol.type == STIXPatternParser.FloatLiteral: return stix2.FloatConstant(node.getText()) elif node.symbol.type == STIXPatternParser.HexLiteral: return stix2.HexConstant(node.getText()) elif node.symbol.type == STIXPatternParser.BinaryLiteral: return stix2.BinaryConstant(node.getText()) elif node.symbol.type == STIXPatternParser.StringLiteral: return stix2.StringConstant(node.getText().strip('\'')) elif node.symbol.type == STIXPatternParser.BoolLiteral: return stix2.BooleanConstant(node.getText()) elif node.symbol.type == STIXPatternParser.TimestampLiteral: return stix2.TimestampConstant(node.getText()) # TODO: timestamp else: return node
def test_boolean_constant(data, result): boolean = stix2.BooleanConstant(data) assert boolean.value == result
def test_invalid_boolean_constant(): with pytest.raises(ValueError): stix2.BooleanConstant('foo')
def test_invalid_boolean_constant(): with pytest.raises(ValueError) as excinfo: stix2.BooleanConstant('foo') assert 'must be a boolean' in str(excinfo)