def test_queue_option_keyword_too_few_arguments(self):
        keywords = ErtKeywords()
        clb = ConfigurationLineBuilder(keywords)

        test_line = "QUEUE_OPTION LSF LSF_BJOBS_CMD"

        clb.processLine(test_line)
        config_line = clb.configurationLine()

        arguments = config_line.arguments()

        self.assertEqual(len(arguments), 3)

        self.assertEqual(arguments[0].value(), "LSF")
        self.assertEqual(arguments[1].value(), "LSF_BJOBS_CMD")
        self.assertEqual(arguments[2].value(), "")

        self.assertFalse(
            config_line.validationStatusForToken(config_line.keyword()))

        self.assertTrue(config_line.validationStatusForToken(arguments[0]))
        self.assertTrue(config_line.validationStatusForToken(arguments[1]))
        self.assertFalse(config_line.validationStatusForToken(arguments[2]))

        self.assertEqual(
            config_line.validationStatusForToken(arguments[2]).message(),
            ArgumentDefinition.MISSING_ARGUMENT)
示例#2
0
    def __init__(self, document):
        QSyntaxHighlighter.__init__(self, document)

        self.clb = ConfigurationLineBuilder(ErtKeywords())

        self.comment_format = QTextCharFormat()
        self.comment_format.setForeground(QColor(0, 128, 0))
        self.comment_format.setFontItalic(True)

        self.keyword_format = QTextCharFormat()
        self.keyword_format.setForeground(QColor(200, 100, 0))
        # self.keyword_format.setFontWeight(QFont.Bold)

        self.error_format = QTextCharFormat()
        # self.error_format.setForeground(QColor(255, 0, 0))
        self.error_format.setUnderlineStyle(QTextCharFormat.WaveUnderline)
        self.error_format.setUnderlineColor(QColor(255, 0, 0))

        self.search_format = QTextCharFormat()
        self.search_format.setBackground(QColor(220, 220, 220))

        self.builtin_format = QTextCharFormat()
        self.builtin_format.setForeground(QColor(0, 170, 227))

        self.search_string = ""
    def test_unknown_keyword_with_comment(self):
        keywords = ErtKeywords()
        clb = ConfigurationLineBuilder(keywords)

        test_line = "KEYWORD nothing --comment"

        clb.processLine(test_line)

        self.assertTrue(clb.hasConfigurationLine())

        config_line = clb.configurationLine()
        keyword = config_line.keyword()
        self.assertFalse(config_line.validationStatusForToken(keyword))
        message = ConfigurationLine.UNKNOWN_KEYWORD + '\n' + ConfigurationLine.ARGUMENT_ERROR + '\n' + ConfigurationLine.ARGUMENT_NOT_EXPECTED
        self.assertEqual(
            config_line.validationStatusForToken(keyword).message(), message)

        self.assertEqual(keyword.value(), "KEYWORD")
        arguments = config_line.arguments()

        self.assertEqual(arguments[0].value(), "nothing")
        self.assertIsNone(keyword.keywordDefinition())

        self.assertTrue(clb.hasComment())
        self.assertEqual(clb.commentIndex(), 16)

        self.assertFalse(config_line.validationStatusForToken(arguments[0]))
        self.assertEqual(
            config_line.validationStatusForToken(arguments[0]).message(),
            ConfigurationLine.ARGUMENT_NOT_EXPECTED)
示例#4
0
    def __init__(self, document):
        QSyntaxHighlighter.__init__(self, document)

        self.clb = ConfigurationLineBuilder(ErtKeywords())


        self.comment_format = QTextCharFormat()
        self.comment_format.setForeground(QColor(0, 128, 0))
        self.comment_format.setFontItalic(True)

        self.keyword_format = QTextCharFormat()
        self.keyword_format.setForeground(QColor(200, 100, 0))
        # self.keyword_format.setFontWeight(QFont.Bold)

        self.error_format = QTextCharFormat()
        # self.error_format.setForeground(QColor(255, 0, 0))
        self.error_format.setUnderlineStyle(QTextCharFormat.WaveUnderline)
        self.error_format.setUnderlineColor(QColor(255, 0, 0))

        self.search_format = QTextCharFormat()
        self.search_format.setBackground(QColor(220, 220, 220))

        self.builtin_format = QTextCharFormat()
        self.builtin_format.setForeground(QColor(0, 170, 227))

        self.search_string = ""
    def test_unknown_keyword_with_comment(self):
        keywords = ErtKeywords()
        clb = ConfigurationLineBuilder(keywords)

        test_line = "KEYWORD nothing --comment"

        clb.processLine(test_line)

        self.assertTrue(clb.hasConfigurationLine())

        config_line = clb.configurationLine()
        keyword = config_line.keyword()
        self.assertFalse(config_line.validationStatusForToken(keyword))
        message = ConfigurationLine.UNKNOWN_KEYWORD + '\n' + ConfigurationLine.ARGUMENT_ERROR + '\n' + ConfigurationLine.ARGUMENT_NOT_EXPECTED
        self.assertEqual(config_line.validationStatusForToken(keyword).message(), message)

        self.assertEqual(keyword.value(), "KEYWORD")
        arguments = config_line.arguments()

        self.assertEqual(arguments[0].value(), "nothing")
        self.assertIsNone(keyword.keywordDefinition())

        self.assertTrue(clb.hasComment())
        self.assertEqual(clb.commentIndex(), 16)

        self.assertFalse(config_line.validationStatusForToken(arguments[0]))
        self.assertEqual(config_line.validationStatusForToken(arguments[0]).message(), ConfigurationLine.ARGUMENT_NOT_EXPECTED)
    def test_num_realizations_no_argument(self):
        keywords = ErtKeywords()
        clb = ConfigurationLineBuilder(keywords)

        test_line = "NUM_REALIZATIONS"

        clb.processLine(test_line)

        self.assertTrue(clb.hasConfigurationLine())

        config_line = clb.configurationLine()

        self.assertEqual(config_line.keyword().value(), "NUM_REALIZATIONS")
        self.assertEqual(config_line.keyword().keywordDefinition(), keywords["NUM_REALIZATIONS"].keywordDefinition())

        arguments = config_line.arguments()
        self.assertEqual(len(arguments), 1)

        self.assertFalse(config_line.validationStatusForToken(config_line.keyword()))
        self.assertFalse(config_line.validationStatusForToken(arguments[0]))
    def test_queue_option_keyword(self):
        keywords = ErtKeywords()
        clb = ConfigurationLineBuilder(keywords)

        test_line = "QUEUE_OPTION LSF LSF_BJOBS_CMD STRING AND STRING"

        clb.processLine(test_line)
        config_line = clb.configurationLine()

        arguments = config_line.arguments()

        self.assertEqual(len(arguments), 3)
        self.assertEqual(arguments[0].value(), "LSF")
        self.assertEqual(arguments[1].value(), "LSF_BJOBS_CMD")
        self.assertEqual(arguments[2].value(), "STRING AND STRING")

        print(config_line.validationStatusForToken(config_line.keyword()))

        self.assertTrue(config_line.validationStatusForToken(arguments[0]))
        self.assertTrue(config_line.validationStatusForToken(arguments[1]))
        self.assertTrue(config_line.validationStatusForToken(arguments[2]))
    def test_queue_option_keyword(self):
        keywords = ErtKeywords()
        clb = ConfigurationLineBuilder(keywords)

        test_line = "QUEUE_OPTION LSF LSF_BJOBS_CMD STRING AND STRING"

        clb.processLine(test_line)
        config_line = clb.configurationLine()

        arguments = config_line.arguments()

        self.assertEqual(len(arguments), 3)
        self.assertEqual(arguments[0].value(), "LSF")
        self.assertEqual(arguments[1].value(), "LSF_BJOBS_CMD")
        self.assertEqual(arguments[2].value(), "STRING AND STRING")

        print(config_line.validationStatusForToken(config_line.keyword()))

        self.assertTrue(config_line.validationStatusForToken(arguments[0]))
        self.assertTrue(config_line.validationStatusForToken(arguments[1]))
        self.assertTrue(config_line.validationStatusForToken(arguments[2]))
    def test_queue_option_keyword_too_few_arguments(self):
        keywords = ErtKeywords()
        clb = ConfigurationLineBuilder(keywords)

        test_line = "QUEUE_OPTION LSF LSF_BJOBS_CMD"

        clb.processLine(test_line)
        config_line = clb.configurationLine()

        arguments = config_line.arguments()

        self.assertEqual(len(arguments), 3)

        self.assertEqual(arguments[0].value(), "LSF")
        self.assertEqual(arguments[1].value(), "LSF_BJOBS_CMD")
        self.assertEqual(arguments[2].value(), "")

        self.assertFalse(config_line.validationStatusForToken(config_line.keyword()))

        self.assertTrue(config_line.validationStatusForToken(arguments[0]))
        self.assertTrue(config_line.validationStatusForToken(arguments[1]))
        self.assertFalse(config_line.validationStatusForToken(arguments[2]))

        self.assertEqual(config_line.validationStatusForToken(arguments[2]).message(), ArgumentDefinition.MISSING_ARGUMENT)
    def test_num_realizations(self):
        keywords = ErtKeywords()
        clb = ConfigurationLineBuilder(keywords)

        test_line = "NUM_REALIZATIONS 25"

        clb.processLine(test_line)

        self.assertTrue(clb.hasConfigurationLine())
        self.assertFalse(clb.hasComment())
        self.assertEqual(clb.commentIndex(), -1)

        config_line = clb.configurationLine()

        self.assertEqual(config_line.keyword().value(), "NUM_REALIZATIONS")
        self.assertEqual(config_line.keyword().keywordDefinition(), keywords["NUM_REALIZATIONS"].keywordDefinition())
        self.assertEqual(config_line.arguments()[0].value(), "25")
示例#11
0
    def test_num_realizations(self):
        keywords = ErtKeywords()
        clb = ConfigurationLineBuilder(keywords)

        test_line = "NUM_REALIZATIONS 25"

        clb.processLine(test_line)

        self.assertTrue(clb.hasConfigurationLine())
        self.assertFalse(clb.hasComment())
        self.assertEqual(clb.commentIndex(), -1)

        config_line = clb.configurationLine()

        self.assertEqual(config_line.keyword().value(), "NUM_REALIZATIONS")
        self.assertEqual(config_line.keyword().keywordDefinition(), keywords["NUM_REALIZATIONS"].keywordDefinition())
        self.assertEqual(config_line.arguments()[0].value(), "25")
    def test_num_realizations_no_argument(self):
        keywords = ErtKeywords()
        clb = ConfigurationLineBuilder(keywords)

        test_line = "NUM_REALIZATIONS"

        clb.processLine(test_line)

        self.assertTrue(clb.hasConfigurationLine())

        config_line = clb.configurationLine()

        self.assertEqual(config_line.keyword().value(), "NUM_REALIZATIONS")
        self.assertEqual(config_line.keyword().keywordDefinition(), keywords["NUM_REALIZATIONS"].keywordDefinition())

        arguments = config_line.arguments()
        self.assertEqual(len(arguments), 1)

        self.assertFalse(config_line.validationStatusForToken(config_line.keyword()))
        self.assertFalse(config_line.validationStatusForToken(arguments[0]))
示例#13
0
class KeywordHighlighter(QSyntaxHighlighter):
    def __init__(self, document):
        QSyntaxHighlighter.__init__(self, document)

        self.clb = ConfigurationLineBuilder(ErtKeywords())

        self.comment_format = QTextCharFormat()
        self.comment_format.setForeground(QColor(0, 128, 0))
        self.comment_format.setFontItalic(True)

        self.keyword_format = QTextCharFormat()
        self.keyword_format.setForeground(QColor(200, 100, 0))
        # self.keyword_format.setFontWeight(QFont.Bold)

        self.error_format = QTextCharFormat()
        # self.error_format.setForeground(QColor(255, 0, 0))
        self.error_format.setUnderlineStyle(QTextCharFormat.WaveUnderline)
        self.error_format.setUnderlineColor(QColor(255, 0, 0))

        self.search_format = QTextCharFormat()
        self.search_format.setBackground(QColor(220, 220, 220))

        self.builtin_format = QTextCharFormat()
        self.builtin_format.setForeground(QColor(0, 170, 227))

        self.search_string = ""

    def formatKeyword(self, keyword, validation_status):
        assert isinstance(keyword, Keyword)
        if keyword.hasKeywordDefinition():
            keyword_format = QTextCharFormat(self.keyword_format)

            if not validation_status:
                keyword_format.merge(self.error_format)

            self.formatToken(keyword, keyword_format)
        else:
            self.formatToken(keyword, self.error_format)

    def highlightBlock(self, complete_block):
        try:
            block = unicode(complete_block)
        except NameError:
            block = complete_block

        self.clb.processLine(block)

        if self.clb.hasComment():
            self.setFormat(self.clb.commentIndex(),
                           len(block) - self.clb.commentIndex(),
                           self.comment_format)

        if not self.clb.hasConfigurationLine():
            count = len(block)

            if self.clb.hasComment():
                count = self.clb.commentIndex()

            self.setFormat(0, count, self.error_format)

        if self.clb.hasConfigurationLine():
            cl = self.clb.configurationLine()
            self.setCurrentBlockUserData(ConfigurationLineUserData(cl))

            self.formatKeyword(cl.keyword(),
                               cl.validationStatusForToken(cl.keyword()))

            arguments = cl.arguments()

            for argument in arguments:
                if not argument.hasArgumentDefinition():
                    pass

                elif argument.argumentDefinition().isBuiltIn():
                    self.formatToken(argument, self.builtin_format)

                if not cl.validationStatusForToken(argument):
                    self.formatToken(argument, self.error_format)

        if self.search_string != "":
            for match in re.finditer("(%s)" % self.search_string,
                                     complete_block):
                self.setFormat(match.start(1),
                               match.end(1) - match.start(1),
                               self.search_format)

    def setSearchString(self, string):
        try:
            if self.search_string != unicode(string):
                self.search_string = unicode(string)
                self.rehighlight()
        except NameError:
            if self.search_string != string:
                self.search_string = string
                self.rehighlight()

    def formatToken(self, token, highlight_format):
        self.setFormat(token.fromIndex(), token.count(), highlight_format)
示例#14
0
class KeywordHighlighter(QSyntaxHighlighter):
    def __init__(self, document):
        QSyntaxHighlighter.__init__(self, document)

        self.clb = ConfigurationLineBuilder(ErtKeywords())


        self.comment_format = QTextCharFormat()
        self.comment_format.setForeground(QColor(0, 128, 0))
        self.comment_format.setFontItalic(True)

        self.keyword_format = QTextCharFormat()
        self.keyword_format.setForeground(QColor(200, 100, 0))
        # self.keyword_format.setFontWeight(QFont.Bold)

        self.error_format = QTextCharFormat()
        # self.error_format.setForeground(QColor(255, 0, 0))
        self.error_format.setUnderlineStyle(QTextCharFormat.WaveUnderline)
        self.error_format.setUnderlineColor(QColor(255, 0, 0))

        self.search_format = QTextCharFormat()
        self.search_format.setBackground(QColor(220, 220, 220))

        self.builtin_format = QTextCharFormat()
        self.builtin_format.setForeground(QColor(0, 170, 227))

        self.search_string = ""


    def formatKeyword(self, keyword, validation_status):
        assert isinstance(keyword, Keyword)
        if keyword.hasKeywordDefinition():
            keyword_format = QTextCharFormat(self.keyword_format)

            if not validation_status:
                keyword_format.merge(self.error_format)

            self.formatToken(keyword, keyword_format)
        else:
            self.formatToken(keyword, self.error_format)


    def highlightBlock(self, complete_block):
        try:
            block = unicode(complete_block)
        except NameError:
            block = complete_block

        self.clb.processLine(block)


        if self.clb.hasComment():
            self.setFormat(self.clb.commentIndex(), len(block) - self.clb.commentIndex(), self.comment_format)

        if not self.clb.hasConfigurationLine():
            count = len(block)

            if self.clb.hasComment():
                count = self.clb.commentIndex()

            self.setFormat(0, count, self.error_format)


        if self.clb.hasConfigurationLine():
            cl = self.clb.configurationLine()
            self.setCurrentBlockUserData(ConfigurationLineUserData(cl))

            self.formatKeyword(cl.keyword(), cl.validationStatusForToken(cl.keyword()))

            arguments = cl.arguments()

            for argument in arguments:
                if not argument.hasArgumentDefinition():
                    pass

                elif argument.argumentDefinition().isBuiltIn():
                    self.formatToken(argument, self.builtin_format)

                if not cl.validationStatusForToken(argument):
                    self.formatToken(argument, self.error_format)


        if self.search_string != "":
            for match in re.finditer("(%s)" % self.search_string, complete_block):
                self.setFormat(match.start(1), match.end(1) - match.start(1), self.search_format)


    def setSearchString(self, string):
        try:
            if self.search_string != unicode(string):
                self.search_string = unicode(string)
                self.rehighlight()
        except NameError:
            if self.search_string != string:
                self.search_string = string
                self.rehighlight()


    def formatToken(self, token, highlight_format):
        self.setFormat(token.fromIndex(), token.count(), highlight_format)