Example #1
0
    def setUp(self):
        """Setup the query master with some patterns used by the tests"""

        # ISSUE007
        # TODO, pyunit's bright idea is to call setup before each test.  It
        # was defining multiple patterns which was annoying but not a problem.
        # The cleanest way to do things is probably to remove patterns after
        # the test, but we don't have that functionality.  For now just create
        # one pattern to avoid confusion, but do it by hacking in a global
        # variable

        global firstTime

        if not firstTime:
            return
        firstTime = False

        # get the full source name for even and odd sources
        out_of_order_numbers = quilt_test_core.get_source_name(
            "out_of_order_numbers")

        # TODO REad the pattern id from the std output then query that one
        # See ISSUE007 and ISSUE008
        # call quilt_define with the pattern code and name query
        #   dups_follows
        quilt_test_core.call_quilt_script('quilt_define.py', ['-n',
                                                              'out_of_order',
                                                              'source("' + out_of_order_numbers + '","grep")'])
Example #2
0
    def setUp(self):
        """Setup the query master with some patterns used by the tests"""

        # ISSUE007
        # TODO, pyunit's bright idea is to call setup before each test.  It
        # was defining multiple patterns which was annoying but not a problem.
        # The cleanest way to do things is probably to remove patterns after
        # the test, but we don't have that functionality.  For now just create
        # one pattern to avoid confusion, but do it by hacking in a global
        # variable

        global firstTime

        if not firstTime:
            return
        firstTime = False

        # call quilt status and parse out the name of the syslog source
        srcName = quilt_test_core.get_source_name("syslog")

        #        logging.debug("Determined source name as: " + srcName)

        #TODO REad the pattern id from the std output then query that one
        # See ISSUE007 and ISSUE008
        quilt_test_core.call_quilt_script('quilt_define.py', [
            '-n', 'test_pattern',
            '-v', 'SEARCHSTRING', 'the Search string',
            '-m', 'SEARCHSTRING', srcName, 'grep', 'OPTIONS'])
        logging.debug("Defined test_pattern")
Example #3
0
    def test_basic_query(self):
        qstr = 'find me again ' + str(random.random())
        # call quilt_submit "find me again" (check return code)
        quilt_test_core.call_quilt_script('quilt_submit.py',
            [qstr, '-y'], checkCall=False)
        # sleep a small amount
        quilt_test_core.sleep_small()
        # Use QuiltConfig, Call GetSourceManagers, for each one
        # use pyro, create proxy for the smd
        # call GetLastQuery()
        # assure it is equal to "find me again [uniqueval]"
        cfg = quilt_core.QuiltConfig()
        with quilt_core.GetQueryMasterProxy(cfg) as qm:
            smgrs = qm.GetClients("SourceManager")

            for smgr in smgrs:
                clientRec = qm.GetClientRec("SourceManager", smgr)
                with query_master.get_client_proxy(clientRec) as smgrClient:
                    lastQuery = smgrClient.GetLastQuery()
                    # after more functionality was added sources won't be called
                    # unless referenced in the query.  we should no longer
                    # see the unique query string down on the source
                    # we wouldn't anyway because it isn't the ID.  The 
                    # last query stuff was just a hack to get testing in
                    # 0.1.c1, and is added to issue list to remove
                    # TODO see ISSUE004
                    self.assertTrue(lastQuery != qstr)

            # check qmd to be sure that all quilt_submit's have unregistered
            # do this by accessing Config, finding qmd name,
            qs = qm.GetClients("QuiltSubmit")
            # make sure list is empty
            self.assertTrue(len(qs) == 0)
Example #4
0
    def test_logging(self):
        """
        calls quilt_status with an invalid key and a specification
        for a log file, then Checks that the log file exists
        """

        # create a randomize log file name in /tmp
        rnum = random.randint(10000, 99999)
        logname = "log" + str(rnum) + ".log"
        logpath = os.path.join('/tmp', logname)

        # call quilt submit -y logging_not_a_pattern -l DEBUG --log-file
        #   random_log_file
        queryStr = 'logging_not_a_pattern'
        quilt_test_core.call_quilt_script('quilt_submit.py',
                                          [queryStr, '--log-file', logpath],
                                          whichReturn=sei_core.EXITCODE,
                                          checkCall=False)

        # check resulting log file contains "logging_not_a_pattern"
        exists = 0 == sei_core.run_process(
            'grep "' + queryStr + '" "' + logpath + '" > /dev/null', shell=True,
            whichReturn=sei_core.EXITCODE, checkCall=False)
        self.assertTrue(exists)

        # delete the temp log file
        os.remove(logpath)
Example #5
0
 def check(self, qid):
     o = quilt_test_core.call_quilt_script('quilt_history.py')
     # check it contains query_id
     self.assertTrue(qid in o)
     # call quilt_history query_id
     o = quilt_test_core.call_quilt_script('quilt_history.py', [qid])
     # check it shows good state (completed)
     self.assertTrue(quilt_data.STATE_COMPLETED in o)
Example #6
0
    def test_one_source(self):
        """
        This test assures that a simple case of semantics is tested
        where only one thing is referenced, the results of one source
        query.  Additionally a red herring second variable is specified
        in the pattern, but is not mentioned in the pattern's code, only 
        in the query's variables.  We want to make sure quilt is smart
        enough not to make a useless source query.  An additional query
        is made on the pattern where the second unused variable is
        given a value.  Quilt should still be smart enough not to run
        this source query because it is not mentioned in the pattern code
        """

        # issue a valid query
        o = str(quilt_test_core.call_quilt_script('quilt_submit.py', [
            'semantics_one_source', '-y', '-v', 'WHICH_HOLIDAY', "newyears"
        ]))

        o = self.check_query_and_get_results(o)

        # find some particulars in the results
        occurences = (
            len([m.start() for m in re.finditer(
                "newyears", o)]))
        # + 2 because it occurs in var specs
        self.assertTrue(occurences == 1 + 2)

        occurences = (
            len([m.start() for m in re.finditer(
                "easter", o)]))
        self.assertTrue(occurences == 0)

        occurences = (
            len([m.start() for m in re.finditer(
                "christmass", o)]))
        self.assertTrue(occurences == 0)


        # issue a valid query
        o = str(quilt_test_core.call_quilt_script('quilt_submit.py', [
            'semantics_one_source', '-y', '-v', 'UNUSED', "valentines"
        ]))

        o = self.check_query_and_get_results(o)

        # find some particulars in the results
        occurences = (
            len([m.start() for m in re.finditer(
                "newyears", o)]))
        self.assertTrue(occurences == 1)

        occurences = (
            len([m.start() for m in re.finditer(
                "thanksgiving", o)]))
        self.assertTrue(occurences == 1)
    def test_multi_sources(self):
        """
        check multiple variables, and multiple patterns are functioning
        """

        # defaults specified in source patterns for SEARCHSTRING[4,6]
        o = str(quilt_test_core.call_quilt_script('quilt_submit.py', [
            'bigpattern',
            '-y',
            '-v', 'SEARCHSTRING1', "Occurs_1_time",
            '-v', 'SEARCHSTRING2', "Occurs_3_times",
            '-v', 'SEARCHSTRING3', "word-regexp",
            '-v', 'SEARCHSTRING5', "word-regexp"
        ]))
        # sleep a small amount
        quilt_test_core.sleep_large()

        # capture query_id from std out 
        a = o.index("Query ID is: ") + len(str("Query ID is: "))
        qid = o[a:]

        # issue a valid query

        # call quilt_history query_id
        o = quilt_test_core.call_quilt_script('quilt_history.py', [qid])
        # check it shows good state (completed)
        self.assertTrue(quilt_data.STATE_COMPLETED in o)

        # find some particulars in the results
        occurences = (
            len([m.start() for m in re.finditer(
                "Occurs_1_time", o)]))

        # have to +2 because the search variable 
        # and src query spec is also in the stdout
        self.assertTrue(occurences == 1 + 2)

        occurences = (
            len([m.start() for m in re.finditer(
                "Occurs_3_times", o)]))
        self.assertTrue(occurences == 1 + 4)


        # have no + 1, these are defaults set from src pattern

        occurences = (
            len([m.start() for m in re.finditer(
                "src default for pat2 occurs twice", o)]))
        self.assertTrue(occurences == 3)

        occurences = (
            len([m.start() for m in re.finditer(
                "src default for pat1 occurs once", o)]))
        self.assertTrue(occurences == 2)
    def setUp(self):
        """Setup the query master with some patterns used by the tests"""

        # ISSUE007
        # TODO, pyunit's bright idea is to call setup before each test.  It
        # was defining multiple patterns which was annoying but not a problem.
        # The cleanest way to do things is probably to remove patterns after
        # the test, but we don't have that functionality.  For now just create
        # one pattern to avoid confusion, but do it by hacking in a global
        # variable

        global firstTime

        if not firstTime:
            return
        firstTime = False

        # get the full source name for even and odd sources
        even_numbers = quilt_test_core.get_source_name(
            "even_numbers")
        odd_numbers = quilt_test_core.get_source_name(
            "odd_numbers")

        # define template pattern code string
        followsTemplate = "follows(5, source('$EVEN','grep'),source('$ODD','grep'))"

        # replace EVEN and ODD variables in the template with full names
        replacements = {'EVEN': even_numbers, 'ODD': odd_numbers}
        followsTemplate = Template(followsTemplate)
        followsPatCode = followsTemplate.safe_substitute(replacements)


        # TODO REad the pattern id from the std output then query that one
        # See ISSUE007 and ISSUE008
        # call quilt_define with the pattern code and name query
        #   dups_follows
        quilt_test_core.call_quilt_script('quilt_define.py', ['-n',
            'dups_follows', followsPatCode])

        # define template pattern code string
        concurrentTemplate = "concurrent(source('$EVEN','grep'),source('$EVEN','grep'), source('$EVEN','grep'))"

        # replace EVEN variable in the template with full source name
        concurrentTemplate = Template(concurrentTemplate)
        concurrentPatCode = concurrentTemplate.safe_substitute(replacements)

        # TODO REad the pattern id from the std output then query that one
        # See ISSUE007 and ISSUE008
        # call quilt_define with the pattern code and name query
        #   dups_concurrent

        quilt_test_core.call_quilt_script('quilt_define.py', ['-n',
            'dups_concurrent', concurrentPatCode])
Example #9
0
    def test_compare_value(self):
        """
        Test will submit a query for each comparison operator and verify
        results.  This will use a field on the lhs and a value on the rhs
        of the operator
        """

        # initialize a dictionary, where key's are the comparison operators
        #   and value is a tuple.  The first element of the tuple is
        #   the value to use in the query code, and the second element
        #   of the tuple is the  string that should appear in the results
        cases = {
            '<': (11, 'boxingday'),
            '<=': (10, 'boxingday'),
            '>': (100000, 'stpatricks'),
            '>=': (100000, 'independenceday'),
            '==': (10000, 'newyears'),
            '!=': (100001, 'boxingday')
        }

        # for each key and value pair
        for operator, (value, answer) in cases.items():
            # submit the operators_comparefields query
            #   pass key as value for OPERATOR variable
            #   pass first element of value tuple as VALUE variable
            o = str(quilt_test_core.call_quilt_script('quilt_submit.py', [
                '-y', 'operators_comparevalue', '-v', 'OPERATOR', operator,
                '-v', 'VALUE', str(value)]))
            # Assure proper execution, and get results from quilt_history
            o = self.check_query_and_get_results3(o)
            # check results contain one instance of second part of value
            #   tuple
            self.contains(o, answer, 1)
Example #10
0
    def test_compare_fields(self):
        """
        Test will submit a query for each comparison operator and verify
        results.  This will use a field on the lhs and rhs of the operator
        """

        # initialize a dictionary, where key's are the comparison operators
        # and value is a string that should appear in the results
        cases = {
            '<': 'boxingday',
            '<=': 'memorialday',
            '>': 'stpatricks',
            '>=': 'independenceday'
        }

        # for each key and value pair
        for key, value in cases.items():
            # submit the operators_comparefields query
            #   pass key as value for operator variable
            o = str(quilt_test_core.call_quilt_script('quilt_submit.py', [
                '-y', 'operators_comparefields', '-v', 'OPERATOR', key]))

            # Assure proper execution, and get results from quilt_history
            o = self.check_query_and_get_results3(o)
            # check results contain one instance of "value"
            self.contains(o, value, 1)
Example #11
0
    def test_equals_literal(self):
        """
        This test assures a case where a results list is matched against
        a literal string.  
        """

        # issue valid query for christian_holidays
        # call quilt_submit christian_holidays -y 
        o = str(quilt_test_core.call_quilt_script('quilt_submit.py', [
            'semantics_equals_literal', '-y'
        ]))

        # Check results
        # call quilt_history query_id
        # capture stdout, assure good exitcode
        o = self.check_query_and_get_results(o)

        # find some particulars in the results
        # assure output contains "christmass"
        occurences = (
            len([m.start() for m in re.finditer(
                "christmass", o)]))
        self.assertTrue(occurences == 1)

        # assure output contains no secular_holidays
        occurences = (
            len([m.start() for m in re.finditer(
                "boxingday", o)]))
        self.assertTrue(occurences == 0)
Example #12
0
 def test_status(self):
     # check for the query pattern
     # call quilt_status 
     # check error code and output contains
     #   "test_pattern" and "syslog"
     o = quilt_test_core.call_quilt_script('quilt_status.py')
     self.assertTrue('test_pattern' in o)
Example #13
0
    def test_qand(self):
        """
        This test assures the operation of the 'qand' quilt language
        and function.  It uses a pattern which selects small and medium
        number sources.  it 'quand's' them together which takes the
        intersection.  The result should be the only number where the two
        sets of numbers intersect
        """

        # issue the query using the qand pattern
        o = str(quilt_test_core.call_quilt_script('quilt_submit.py', [
            'semantics_qand', '-y'
        ]))
        # assure the query is successful, and get results
        o = self.check_query_and_get_results(o)

        # check that results contain one correct number
        occurences = (
            len([m.start() for m in re.finditer(
                "{'timestamp': 10}", o)]))
        self.assertTrue(occurences == 1)
        # check than number from LHS is not in intersection

        occurences = (
            len([m.start() for m in re.finditer(
                "{'timestamp': 9}", o)]))
        self.assertTrue(occurences == 0)
Example #14
0
    def test_order(self):
        """
        This test queries a source whose data is out fo order.  The
        configuration of the source pattern indicates that the data is out
        of order and quilt should transform it to ordered behind the
        scenes.  We simply perform a query in the normal matter and assure
        result is sorted
        """

        # issue a valid query
        # Assure proper execution, and get results from quilt_history
        o = str(quilt_test_core.call_quilt_script('quilt_submit.py', [
            '-y', 'out_of_order']))

        o = self.check_query_and_get_results3(o)

        # Check results
        #   assure that results are in order
        l = []
        for i in xrange(1, 6):
            searchStr = "{'timestamp': " + str(i) + '}'
            index = o.find(searchStr)
            logging.debug("looking for string: " + searchStr)
            self.assertTrue(index != -1)
            l.append(index)

        isSorted = all(l[i] <= l[i + 1] for i in xrange(len(l) - 1))
        self.assertTrue(isSorted)
Example #15
0
    def test_qor(self):
        """
        This test assures the operation of the 'qor' quilt language
        or function.  It uses a pattern which selects small and medium
        number sources.  it 'qor's' them together which takes the
        union.  The result should be the contents of the union of the
        two input sets
        """

        # issue the query using the qor pattern
        o = str(quilt_test_core.call_quilt_script('quilt_submit.py', [
            'semantics_qor', '-y'
        ]))
        # assure the query is successful, and get results
        o = self.check_query_and_get_results(o)

        # check that results contain one number only in small
        occurences = (
            len([m.start() for m in re.finditer(
                "{'timestamp': 9}", o)]))
        self.assertTrue(occurences == 1)

        # check that results contain one number only in med
        occurences = (
            len([m.start() for m in re.finditer(
                "{'timestamp': 20}", o)]))
        self.assertTrue(occurences == 1)
        # check that results contain one number only from both
        occurences = (
            len([m.start() for m in re.finditer(
                "{'timestamp': 10}", o)]))
        self.assertTrue(occurences == 1)
Example #16
0
    def test_nested_concurrent(self):
        """
        This test covers a nested case where operator operates on
        results of a literal comparison.
        Also covers case where pattern has no mapped
        variables, but still references sources
        """

        # issue valid query for concurrent_holidays
        # call quilt_submit semantics_concurrent -y 
        o = str(quilt_test_core.call_quilt_script('quilt_submit.py', [
            'semantics_nested', '-y'
        ]))

        # Check results
        # call quilt_history query_id
        # capture stdout, assure good exitcode
        o = self.check_query_and_get_results(o)

        # assure output contains laborday and ashwednesday
        occurences = (
            len([m.start() for m in re.finditer(
                "ashwednesday", o)]))
        self.assertTrue(occurences == 1)

        # assure output contains no christmass
        occurences = (
            len([m.start() for m in re.finditer(
                "christmass", o)]))
        self.assertTrue(occurences == 0)
Example #17
0
    def test_basic_queue(self):

        qstr = 'find me again ' + str(random.random())

        # define the query
        o = quilt_test_core.call_quilt_script('quilt_define.py',
            ['-n', qstr])

        # call quilt_submit "find me again" (check return code)
        o = str(quilt_test_core.call_quilt_script('quilt_submit.py',
            [qstr, '-y']))
        # sleep a small amount
        quilt_test_core.sleep_small()

        a = o.index("Query ID is: ") + len(str("Query ID is: "))
        qid = o[a:]

        self.assertTrue(len(qid) > 0)

        # call quilt_q (check return code, capture output)
        o = quilt_test_core.call_quilt_script('quilt_q.py')


        # call quilt_q -q query_id (check return code, capture output)
        o = quilt_test_core.call_quilt_script('quilt_q.py', [qid])

        # assure output contains same query id as before
        self.assertTrue(len(o) > 0)

        # call quilt_q -q FAKEid (check return code, capture output)
        o = quilt_test_core.call_quilt_script('quilt_q.py', [
            qid + 'FAKE'])

        # assure no output
        self.assertTrue(o is None or len(o) == 0)

        # check qmd to be sure that all quilt_q's have unregistered
        # do this by accessing Config, finding qmd name,
        # create pyro proxy for qmd, call getRegisteredObjects(type(QuiltQ))
        # make sure list is empty

        with quilt_core.GetQueryMasterProxy() as qm:
            # check qmd to be sure that all quilt_q's have unregistered
            qs = qm.GetClients("QuiltQueue")
            # make sure list is empty
            self.assertTrue(len(qs) == 0)
Example #18
0
 def query(self, searchString):
     o = str(quilt_test_core.call_quilt_script('quilt_submit.py', [
         '-y', '-v', 'SEARCHSTRING', searchString, 'test_pattern']))
     # capture query_id from std out 
     a = o.index("Query ID is: ") + len(str("Query ID is: "))
     qid = o[a:]
     self.assertTrue(len(qid) > 0)
     # sleep a small amount
     quilt_test_core.sleep_medium()
     return qid
Example #19
0
    def test_lessthan(self):
        """
        submits the operators_lessthan pattern.  Checks that that the
        result only contains boxing day
        """

        # issue a valid query
        # Assure proper execution, and get results from quilt_history
        o = str(quilt_test_core.call_quilt_script('quilt_submit.py', [
            '-y', 'operators_lessthan']))

        o = self.check_query_and_get_results3(o)
        self.contains(o, 'boxingday', 1)
        self.contains(o, 'valentines', 0)
Example #20
0
    def setUp(self):
        """Setup the query master with some patterns used by the tests"""

        # ISSUE007
        # TODO, pyunit's bright idea is to call setup before each test.  It
        # was defining multiple patterns which was annoying but not a problem.
        # The cleanest way to do things is probably to remove patterns after
        # the test, but we don't have that functionality.  For now just create
        # one pattern to avoid confusion, but do it by hacking in a global
        # variable

        global firstTime

        if not firstTime:
            return
        firstTime = False

        syslog = quilt_test_core.get_source_name("syslog")
        multisource = quilt_test_core.get_source_name("multipattern")

        #TODO REad the pattern id from the std output then query that one
        # See ISSUE007 and ISSUE008
        quilt_test_core.call_quilt_script('quilt_define.py', [
            '-n', "bigpattern",
            '-v', 'SEARCHSTRING1', 'the Search string1',
            '-v', 'SEARCHSTRING2', 'the Search string2',
            '-v', 'SEARCHSTRING3', 'the Search string3',
            '-v', 'SEARCHSTRING4', 'the Search string4',
            '-v', 'SEARCHSTRING5', 'the Search string5',
            '-v', 'SEARCHSTRING6', 'the Search string6',
            '-m', 'SEARCHSTRING1', syslog, 'grep', 'OPTIONS',
            '-m', 'SEARCHSTRING2', syslog, 'grep', 'OPTIONS', 'fooInst',
            '-m', 'SEARCHSTRING3', multisource, 'pat1', 'PAT1SRCVAR1',
            '-m', 'SEARCHSTRING4', multisource, 'pat1', 'PAT1SRCVAR2',
            '-m', 'SEARCHSTRING5', multisource, 'pat2', 'PAT2SRCVAR1',
            '-m', 'SEARCHSTRING6', multisource, 'pat2', 'PAT2SRCVAR2'
        ])
Example #21
0
    def check_query_and_get_results3(self, submitStdout):
        # sleep a small amount
        quilt_test_core.sleep_small()

        o = submitStdout
        # capture query_id from std out 
        a = o.index("Query ID is: ") + len(str("Query ID is: "))
        qid = o[a:]

        # call quilt_history query_id
        o = quilt_test_core.call_quilt_script('quilt_history.py', [qid])
        # check it shows good state (completed)
        self.assertTrue(quilt_data.STATE_COMPLETED in o)

        return o
Example #22
0
    def test_valid_query_all_results(self):
        # issue a valid query
        # call quilt_submit test_pattern -y -v SEARCHSTRING Occurs_1_time
        qid = self.query(".")

        # check that the query is in the history showing good state
        self.check(qid)

        # call quilt_history query_id
        o = quilt_test_core.call_quilt_script('quilt_history.py', [qid])
        # check it shows good state (completed)
        self.assertTrue(quilt_data.STATE_COMPLETED in o)
        #   assure there are many results
        occurences = (
            len([m.start() for m in re.finditer('\n', o)]))
        self.assertTrue(occurences > 4 + 2)
    def test_follows(self):
        """
        submits the dups_follows pattern and assures that no duplicates
        are reported Also assures that correct values are placed in
        results
        """

        # issue a valid query
        # Assure proper execution, and get results from quilt_history
        o = str(quilt_test_core.call_quilt_script('quilt_submit.py', [
            '-y', 'dups_follows']))

        o = self.check_query_and_get_results2(o)

        self.contains_once(o, "{'timestamp': 3}")
        self.contains_once(o, "{'timestamp': 5}")
        self.contains_once(o, "{'timestamp': 7}")
        self.contains_once(o, "{'timestamp': 9}")
Example #24
0
    def test_valid_query_no_results(self):
        # issue a valid query
        # call quilt_submit test_pattern -y -v SEARCHSTRING Occurs_1_time
        qid = self.query("Occurs_no_times")

        # check that the query is in the history showing good state
        self.check(qid)

        # call quilt_history query_id
        o = quilt_test_core.call_quilt_script('quilt_history.py', [qid])
        # check it shows good state (completed)
        self.assertTrue(quilt_data.STATE_COMPLETED in o)
        #   text "Occurs_no_times"
        #   assure no results
        occurences = (
            len([m.start() for m in re.finditer('Occurs_no_times', o)]))
        # have to +2 because the search variable is also in the stdout
        # and src query spec
        self.assertTrue(occurences == 0 + 2)
Example #25
0
    def test_until(self):
        """
        This test assures the operation of the 'until' quilt language
        function.  It uses a pattern which selects secular holidays 
        until a christian holiday occurs.  We expect to see newyears, 
        and valentines
        """
        # issue valid query for concurrent_holidays
        # call quilt_submit semantics_concurrent -y 
        o = str(quilt_test_core.call_quilt_script('quilt_submit.py', [
            'semantics_until', '-y'
        ]))

        # Check results
        # call quilt_history query_id
        # capture stdout, assure good exitcode
        o = self.check_query_and_get_results(o)

        # assure output contains ashwednesday
        occurences = (
            len([m.start() for m in re.finditer(
                "valentines", o)]))
        self.assertTrue(occurences == 1)
        # assure output contains no christmass
        occurences = (
            len([m.start() for m in re.finditer(
                "newyears", o)]))
        self.assertTrue(occurences == 1)


        # assure output contains no valentines
        occurences = (
            len([m.start() for m in re.finditer(
                "easter", o)]))
        self.assertTrue(occurences == 0)

        # assure output contains no boxingday
        occurences = (
            len([m.start() for m in re.finditer(
                "boxingday", o)]))
        self.assertTrue(occurences == 0)
Example #26
0
    def setUp(self):
        """Setup the query master with some patterns used by the tests"""

        # ISSUE007
        # TODO, pyunit's bright idea is to call setup before each test.  It
        # was defining multiple patterns which was annoying but not a problem.
        # The cleanest way to do things is probably to remove patterns after
        # the test, but we don't have that functionality.  For now just create
        # one pattern to avoid confusion, but do it by hacking in a global
        # variable

        global firstTime

        if not firstTime:
            return
        firstTime = False

        christian_holidays = quilt_test_core.get_source_name(
            "christian_holidays")
        secular_holidays = quilt_test_core.get_source_name(
            "secular_holidays")

        #TODO REad the pattern id from the std output then query that one
        # See ISSUE007 and ISSUE008
        quilt_test_core.call_quilt_script('quilt_define.py', [
            'source("' + secular_holidays + '","grep")',
            '-n', 'semantics_one_source',
            '-v', 'WHICH_HOLIDAY',
            '-v', 'UNUSED',
            '-m', 'WHICH_HOLIDAY', secular_holidays, 'grep', 'GREP_ARGS',
            '-m', 'UNUSED', christian_holidays, 'grep', 'GREP_ARGS'
        ])


        #TODO REad the pattern id from the std output then query that one
        # See ISSUE007 and ISSUE008
        quilt_test_core.call_quilt_script('quilt_define.py', [
            'at(source("' + christian_holidays + '","grep"))==12',
            '-n', 'semantics_equals_literal'
        ])

        #TODO REad the pattern id from the std output then query that one
        # See ISSUE007 and ISSUE008
        quilt_test_core.call_quilt_script('quilt_define.py', [
            "concurrent(source('" + christian_holidays + "','grep')," +
            "source('" + secular_holidays + "','grep'))",
            '-n', 'semantics_concurrent'])

        #TODO REad the pattern id from the std output then query that one
        # See ISSUE007 and ISSUE008
        quilt_test_core.call_quilt_script('quilt_define.py', [
            "concurrent(source('" + christian_holidays + "','grep')," +
            "source('" + secular_holidays + "','grep')['major']=='True')",
            '-n', 'semantics_nested'])


        #TODO REad the pattern id from the std output then query that one
        # See ISSUE007 and ISSUE008
        quilt_test_core.call_quilt_script('quilt_define.py', [
            'follows(1,' +
            "source('" + secular_holidays + "','grep')," +
            "source('" + christian_holidays + "','grep'))",
            '-n', 'semantics_follows'
        ])

        #TODO REad the pattern id from the std output then query that one
        # See ISSUE007 and ISSUE008
        quilt_test_core.call_quilt_script('quilt_define.py', [
            'until(' +
            "source('" + secular_holidays + "','grep')," +
            "source('" + christian_holidays + "','grep'))",
            '-n', 'semantics_until'
        ])

        small_numbers = quilt_test_core.get_source_name(
            "small_numbers")
        med_numbers = quilt_test_core.get_source_name(
            "med_numbers")

        #TODO REad the pattern id from the std output then query that one
        # See ISSUE007 and ISSUE008
        quilt_test_core.call_quilt_script('quilt_define.py', [
            'qand(' +
            "source('" + small_numbers + "','grep')," +
            "source('" + med_numbers + "','grep'))",
            '-n', 'semantics_qand'
        ])

        #TODO REad the pattern id from the std output then query that one
        # See ISSUE007 and ISSUE008
        quilt_test_core.call_quilt_script('quilt_define.py', [
            'qor(' +
            "source('" + small_numbers + "','grep')," +
            "source('" + med_numbers + "','grep'))",
            '-n', 'semantics_qor'
        ])
Example #27
0
    def setUp(self):
        """Setup the query master with some patterns used by the tests"""

        # ISSUE007
        # TODO, pyunit's bright idea is to call setup before each test.  It
        # was defining multiple patterns which was annoying but not a problem.
        # The cleanest way to do things is probably to remove patterns after
        # the test, but we don't have that functionality.  For now just create
        # one pattern to avoid confusion, but do it by hacking in a global
        # variable

        global firstTime

        if not firstTime:
            return
        firstTime = False

        # get the full source name for even and odd sources
        christian_holidays = quilt_test_core.get_source_name(
            "christian_holidays")
        secular_holidays = quilt_test_core.get_source_name(
            "secular_holidays")

        # define template pattern code string
        lessThanTemplate = (
            "(source('$SECULAR','grep')['paradesize'] < source('$CHRISTIAN', "
            "'grep')['paradesize'])['paradesize'] < 100")

        # replace EVEN and ODD variables in the template with full names
        replacements = {'CHRISTIAN': christian_holidays,
                       'SECULAR': secular_holidays}
        lessThanTemplate = Template(lessThanTemplate)
        patCode = lessThanTemplate.safe_substitute(replacements)

        # TODO REad the pattern id from the std output then query that one
        # See ISSUE007 and ISSUE008
        # call quilt_define with the pattern code and name query
        #   operators_lessthan
        quilt_test_core.call_quilt_script(
            'quilt_define.py', ['-n', 'operators_lessthan', patCode])

        # define template pattern code string
        template = (
            "(source('$SECULAR','grep')['paradesize'] $OPERATOR source("
            "'$CHRISTIAN', 'grep')['paradesize'])")

        template = Template(template)
        patCode = template.safe_substitute(replacements)

        # TODO REad the pattern id from the std output then query that one
        # See ISSUE007 and ISSUE008
        # call quilt_define with the pattern code and name query
        #   define a variable for which binary operator to use
        #   provide a default value for the variable, this value is mandatory
        #   because the query code is parsed before submission time
        quilt_test_core.call_quilt_script(
            'quilt_define.py', [
                '-n', 'operators_comparefields', patCode, '-v', 'OPERATOR',
                'operator to use in the comparison', '=='])

        # define template pattern code string
        template = (
            "source('$SECULAR','grep')['paradesize'] $OPERATOR $VALUE")

        template = Template(template)
        patCode = template.safe_substitute(replacements)

        # TODO REad the pattern id from the std output then query that one
        # See ISSUE007 and ISSUE008
        # call quilt_define with the pattern code and name query
        #   define a variable for which binary operator to use
        #   define a variable for what value to use on RHS
        #   defaults are required when modifying code with search/replace
        #   variables because template code will not parse
        quilt_test_core.call_quilt_script('quilt_define.py',
            ['-n', 'operators_comparevalue', patCode, '-v', 'OPERATOR',
             'operator to use in the comparison', '==', '-v', 'VALUE',
             'the literal value on the RHS of the comparison','0'])