Example #1
0
    def __init__(self,
                 input_files: list = None,
                 bridge_file: list = None,
                 domain_files: list = None,
                 fact_files: list = None):
        if not input_files:
            input_files = []
        if not domain_files:
            domain_files = []
        if not fact_files:
            fact_files = []
        self.new_input_files = []
        for i in input_files:
            newfile = temporary_text_file(i,
                                          file_extension=".ial",
                                          delete=True)
            newfile.flush()
            self.new_input_files.append(newfile)

        self.new_bridge_files = []
        if bridge_file:
            for b in bridge_file:
                newfile = temporary_text_file(b,
                                              file_extension=".iab",
                                              delete=True)
                newfile.flush()
                self.new_bridge_files.append(newfile)
        super(InstalSingleShotTestRunnerFromText, self).__init__(
            input_files=[n.name for n in self.new_input_files],
            bridge_file=[n.name for n in self.new_bridge_files],
            domain_files=domain_files,
            fact_files=fact_files)
Example #2
0
 def test_trace_multiple(self):
     out_txt = temporary_text_file("", ".txt")
     out_trace = temporary_text_file("", ".tex")
     out_gantt = temporary_text_file("", ".tex")
     return_code = subprocess.call(["../../instaltrace.py", "-x", out_txt.name,
                                    "-t", out_trace.name, "-g", out_gantt.name,
                                    "-j", "cliinvocation/test.json"], stderr=subprocess.DEVNULL, stdout=subprocess.DEVNULL)
     self.assertTrue(return_code == 0)
     self.assertTrue(len(out_txt.read()) > 0)
     self.assertTrue(len(out_trace.read()) > 0)
     self.assertTrue(len(out_gantt.read()) > 0)
Example #3
0
    def __init__(self, ial_files: List[InstalFile],
                 bridge_files: List[InstalFile], lp_files: List[InstalFile],
                 domain_files: List[InstalFile], fact_files: List[InstalFile]):
        self.prelude = temporary_text_file(INSTAL_STANDARD_PRELUDE,
                                           file_extension=".lp",
                                           delete=True)

        self.model_files = self.get_model_files(ial_files, bridge_files) + [
            temporary_text_file(l.read(), file_extension=".lp", delete=True)
            for l in lp_files
        ]

        self.domain_facts = self.get_domains(domain_files)

        self.initial_facts = self.get_initial(fact_files)
        self.answersets = []  # type: List[InstalStateTrace]
Example #4
0
    def run_test(self,
                 query_file,
                 conditions=None,
                 fact_files=None,
                 verbose=None):
        if not verbose:
            verbose = self.verbose
        if not conditions:
            conditions = []
        if not fact_files:
            fact_files = []
        facts = fact_files + self.fact_files
        json_out = temporary_text_file("", file_extension="out.json")
        self.query_function(input_files=self.input_files,
                            bridge_files=([self.bridge_files[0]] if
                                          len(self.bridge_files) > 0 else []),
                            domain_files=self.domain_files,
                            fact_files=facts,
                            json_file=json_out.name,
                            query=query_file)

        if conditions:
            trace = InstalStateTrace.state_trace_from_json_file(json_out.name)
            errors = trace.check_conditions(conditions)
            assert errors == 0
            return 0
        return 0
Example #5
0
    def run_test(self):
        text_out_1 = temporary_text_file("", ".json")
        text_out_2 = temporary_text_file("", ".json")

        instaltrace.instal_trace_keyword(text_file=text_out_1.name,
                                         json_file=self.file1.name)
        instaltrace.instal_trace_keyword(text_file=text_out_2.name,
                                         json_file=self.file2.name)

        text_out_1.seek(0)
        text_out_2.seek(0)
        out_1 = text_out_1.read()
        out_2 = text_out_2.read()

        print(out_1)
        print(out_2)
        assert (out_1 == out_2)
        return out_1, out_2
Example #6
0
    def test_trace_gantt(self):
        out_tex = temporary_text_file("", ".tex")
        return_code = subprocess.call(["../../instaltrace.py", "-g", out_tex.name,
                                       "-j", "cliinvocation/test.json"], stderr=subprocess.DEVNULL, stdout=subprocess.DEVNULL)
        self.assertTrue(return_code == 0)
        self.assertTrue(len(out_tex.read()) > 0)

        output_dir = tempfile.TemporaryDirectory()
        return_code = subprocess.call(["pdflatex", "-output-directory", output_dir.name, "-halt-on-error",  out_tex.name],
                                      stderr=subprocess.DEVNULL, stdout=subprocess.DEVNULL)

        self.assertTrue(return_code == 0)
Example #7
0
    def run_test(self):
        raise InstalTestNotImplemented
        json_out_query = temporary_text_file("", file_extension=".json")
        json_out_solve = temporary_text_file("", file_extension=".json")

        instalsolve.instal__keyword(input_files=self.input_files,
                                    bridge_files=self.bridge_files,
                                    domain_files=self.domain_files,
                                    fact_files=self.fact_files,
                                    query=self.query,
                                    length=self.length,
                                    number=1,
                                    json_file=json_out_query.name)

        instalquery.instal_query_keyword(input_files=self.input_files,
                                         bridge_files=self.bridge_files,
                                         domain_files=self.domain_files,
                                         fact_files=self.fact_files,
                                         query=self.query,
                                         json_file=json_out_solve.name)

        json_test = InstalCompareJSONTestCase(json_out_solve, json_out_query)
        solve_text, query_text = json_test.run_test()
        return solve_text, query_text
 def lp_file(self, directory: str, contents: str, filename: str = None):
     """
         Writes ASP to file.
     """
     if filename is None:
         f = temporary_text_file(contents,
                                 file_extension=".lp",
                                 delete=True)
         return f
     new_file = os.path.basename(filename).replace(".ial", ".lp").replace(
         ".iab", ".lp")
     new_file = directory + new_file
     f = open(new_file, "wt")
     f.write(contents)
     return f
Example #9
0
 def test_trace_demands_json(self):
     out_txt = temporary_text_file("", ".txt")
     return_code = subprocess.call(
         ["../../instaltrace.py", "-x", out_txt.name], stderr=subprocess.DEVNULL, stdout=subprocess.DEVNULL)
     self.assertTrue(return_code != 0)
Example #10
0
 def test_trace_cli_runs(self):
     out_txt = temporary_text_file("", ".txt")
     return_code = subprocess.call(["../../instaltrace.py", "-x", out_txt.name,
                                    "-j", "cliinvocation/test.json"], stderr=subprocess.DEVNULL, stdout=subprocess.DEVNULL)
     self.assertTrue(return_code == 0)