Beispiel #1
0
 def test_no_arguments(self):
     """
     Test "recipy".
     """
     _, stdout = helpers.execute(["recipy"], 1)
     assert len(stdout) > 0, "Expected stdout"
     helpers.assert_matches_regexps(" ".join(stdout), regexps.get_usage())
Beispiel #2
0
 def test_version(self):
     """
     Test "recipy --version".
     """
     _, stdout = helpers.execute(["recipy", "--version"], 0)
     assert len(stdout) > 0, "Expected stdout"
     helpers.assert_matches_regexps(" ".join(stdout), regexps.get_version())
Beispiel #3
0
    def test_latest_diff_json(self, json_flag):
        """
        Test "recipy latest --diff -j|--json".
        """
        _, stdout = helpers.execute(["recipy", "latest", "--diff", json_flag],
                                    0)
        assert len(stdout) > 0, "Expected stdout"
        json_log = json.loads(" ".join(stdout))
        db_log, _ = helpers.get_log(recipyenv.get_recipydb())
        helpers.assert_equal_json_logs(json_log, db_log)
        assert json_log["diff"] == "", "Expected 'diff' to be empty"

        self.modify_script()
        helpers.execute_python(
            [self.script, self.input_file, self.output_file])

        _, stdout = helpers.execute(["recipy", "latest", "--diff", json_flag],
                                    0)
        assert len(stdout) > 0, "Expected stdout"
        json_log = json.loads(" ".join(stdout))
        db_log, _ = helpers.get_log(recipyenv.get_recipydb())
        helpers.assert_equal_json_logs(json_log, db_log)
        assert json_log["diff"] != "", "Expected 'diff' to be non-empty"
        helpers.assert_matches_regexps(
            json_log["diff"], regexps.get_diff(TestRecipy.SCRIPT_NAME))
Beispiel #4
0
 def test_help(self, help_flag):
     """
     Test "recipy -h|--help".
     """
     _, stdout = helpers.execute(["recipy", help_flag], 0)
     assert len(stdout) > 0, "Expected stdout"
     helpers.assert_matches_regexps(" ".join(stdout), regexps.get_help())
Beispiel #5
0
 def test_latest_empty_db(self):
     """
     Test "recipy latest" if no database.
     """
     helpers.clean_recipy()
     _, stdout = helpers.execute(["recipy", "latest"], 0)
     assert len(stdout) > 0, "Expected stdout"
     helpers.assert_matches_regexps(" ".join(stdout),
                                    regexps.get_db_empty())
Beispiel #6
0
 def test_debug(self):
     """
     Test "recipy latest --debug", to look for debug-related output
     on stdout.
     """
     _, stdout = helpers.execute(["recipy", "latest", "--debug"], 0)
     assert len(stdout) > 0, "Expected stdout"
     helpers.assert_matches_regexps(" ".join(stdout),
                                    regexps.get_debug_recipy())
Beispiel #7
0
 def test_latest(self):
     """
     Test "recipy latest".
     """
     _, stdout = helpers.execute(["recipy", "latest"], 0)
     assert len(stdout) > 0, "Expected stdout"
     # Validate using logged data
     db_log, _ = helpers.get_log(recipyenv.get_recipydb())
     helpers.assert_matches_regexps(" ".join(stdout),
                                    regexps.get_stdout(db_log))
Beispiel #8
0
 def test_search_unknown(self, search_flag):
     """
     Test "recipy search [-i|--id|-p|--filepath|-f|--fuzzy
     |-r|--regex] UNKNOWN_VALUE".
     """
     pattern = self.get_unknown_search(search_flag)
     cmd = ["recipy", "search"]
     cmd.extend(pattern)
     _, stdout = helpers.execute(cmd, 0)
     assert len(stdout) > 0, "Expected stdout"
     helpers.assert_matches_regexps(" ".join(stdout),
                                    regexps.get_no_results())
Beispiel #9
0
 def test_general_debug(self):
     """
     If [general].debug is present then debugging information is
     printed.
     """
     recipyrc = recipyenv.get_recipyrc()
     helpers.update_recipyrc(recipyrc, "general", "debug")
     _, stdout = helpers.execute_python(
         [self.script, self.input_file, self.output_file])
     # Order of log statements from get_debug_regexps
     # is tightly-coupled to script.
     helpers.assert_matches_regexps(" ".join(stdout), regexps.get_debug())
Beispiel #10
0
 def test_data_file_diff_outputs_diff(self):
     """
     If [data].file_diff_outputs is present, if output files
     are changed, then there will be 'filediffs' for that run, with
     a 'diff' value describing changes to the output files.
     """
     recipyrc = recipyenv.get_recipyrc()
     helpers.update_recipyrc(recipyrc, "data", "file_diff_outputs")
     # Create empty output file.
     open(self.output_file, 'w').close()
     helpers.execute_python(
         [self.script, self.input_file, self.output_file])
     _, filediffs = helpers.get_log(recipyenv.get_recipydb())
     assert filediffs is not None, "Expected filediffs not to be None"
     assert filediffs["filename"] == self.output_file,\
         ("Expected filediffs['filename'] to be " + self.output_file)
     helpers.assert_matches_regexps(filediffs['diff'],
                                    regexps.get_filediffs())
Beispiel #11
0
    def test_latest_diff(self):
        """
        Test "recipy latest --diff".
        """
        _, stdout = helpers.execute(["recipy", "latest", "--diff"], 0)
        assert len(stdout) > 0, "Expected stdout"
        db_log, _ = helpers.get_log(recipyenv.get_recipydb())
        # Validate standard output.
        helpers.assert_matches_regexps(" ".join(stdout),
                                       regexps.get_stdout(db_log))
        # Validate logged data
        assert db_log["diff"] == "", "Expected 'diff' to be empty"

        self.modify_script()
        helpers.execute_python(
            [self.script, self.input_file, self.output_file])

        _, stdout = helpers.execute(["recipy", "latest", "--diff"], 0)
        assert len(stdout) > 0, "Expected stdout"
        diff_db_log, _ = helpers.get_log(recipyenv.get_recipydb())
        # Validate standard output.
        helpers.assert_matches_regexps(" ".join(stdout),
                                       regexps.get_stdout(diff_db_log))
        helpers.assert_matches_regexps(
            " ".join(stdout), regexps.get_diff(TestRecipy.SCRIPT_NAME))
        # Validate logged data
        assert diff_db_log["diff"] != "", "Expected 'diff' to be non-empty"
        helpers.assert_matches_regexps(
            diff_db_log["diff"], regexps.get_diff(TestRecipy.SCRIPT_NAME))

        # Compare original log to diff log.
        for key in ["inputs", "outputs"]:
            assert len(db_log[key]) == len(diff_db_log[key]),\
                   ("Expected same number of " + key + " files")
            for index in range(0, len(db_log[key])):
                [original_file, _] = db_log[key][index]
                [diff_file, _] = diff_db_log[key][index]
                assert os.path.basename(original_file) ==\
                    os.path.basename(diff_file),\
                    "Expected local file names to be equal"
        # Remove fields that are specific to a run.
        for key in [
                "unique_id", "diff", "date", "exit_date", "command_args",
                "inputs", "outputs"
        ]:
            del db_log[key]
            del diff_db_log[key]
        assert db_log == diff_db_log,\
            ("Expected " + str(db_log) + " to equal " + str(diff_db_log))