Пример #1
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))
Пример #2
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))
Пример #3
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())
Пример #4
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())
Пример #5
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())
Пример #6
0
 def test_latest_json(self, json_flag):
     """
     Test "recipy latest -j|--json".
     """
     _, stdout = helpers.execute(["recipy", "latest", 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)
Пример #7
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())
Пример #8
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())
Пример #9
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))
Пример #10
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())
Пример #11
0
 def test_search_bad_syntax(self, search_flag, json_flag):
     """
     Test "recipy search -p|--filepath|-f|--fuzzy
     |-r|--regex PATTERN VALUE -j|--json".
     """
     db_log, _ = helpers.get_log(recipyenv.get_recipydb())
     unique_id = db_log["unique_id"]
     pattern = self.get_search(search_flag, unique_id)
     cmd = ["recipy", "search"]
     cmd.extend(pattern)
     cmd.append("value")
     cmd.append(json_flag)
     _, _ = helpers.execute(cmd, 1)
Пример #12
0
 def test_search_unknown_json(self, search_flag, json_flag):
     """
     Test "recipy search [-i|--id|-p|--filepath|-f|--fuzzy
     |-r|--regex] UNKNOWN_VALUE -j|--json".
     """
     pattern = self.get_unknown_search(search_flag)
     cmd = ["recipy", "search"]
     cmd.extend(pattern)
     cmd.append(json_flag)
     _, stdout = helpers.execute(cmd, 0)
     assert len(stdout) > 0, "Expected stdout"
     json_logs = json.loads(" ".join(stdout))
     assert json_logs == [], "Expected []"
Пример #13
0
 def test_search_id_hash_prefix(self, id_flag, json_flag):
     """
     Test "recipy search -i|--id HASH_PREFIX [-j|--json]".
     """
     db_log, _ = helpers.get_log(recipyenv.get_recipydb())
     unique_id = db_log["unique_id"]
     half_id = unique_id[0:int(len(unique_id) / 2)]
     _, stdout = helpers.execute(
         ["recipy", "search", id_flag,
          str(half_id), json_flag], 0)
     assert len(stdout) > 0, "Expected stdout"
     json_log = json.loads(" ".join(stdout))
     assert len(json_log) == 1, "Expected a single JSON log"
     helpers.assert_equal_json_logs(json_log[0], db_log)
Пример #14
0
 def test_search(self, search_flag, json_flag):
     """
     Test "recipy search [-p|--filepath|-f|--fuzzy
     |-r|--regex] VALUE -j|--json".
     """
     db_log, _ = helpers.get_log(recipyenv.get_recipydb())
     unique_id = db_log["unique_id"]
     pattern = self.get_search(search_flag, unique_id)
     cmd = ["recipy", "search"]
     cmd.extend(pattern)
     cmd.append(json_flag)
     _, stdout = helpers.execute(cmd, 0)
     assert len(stdout) > 0, "Expected stdout"
     json_log = json.loads(" ".join(stdout))
     # Handle case where 'recipy search HASH' returns a list
     if isinstance(json_log, list):
         json_log = json_log[0]
     helpers.assert_equal_json_logs(json_log, db_log)
Пример #15
0
 def test_search_all(self, search_flag, all_flag, json_flag):
     """
     Test "recipy search [-p|--filepath|-f|--fuzzy
     |-r|--regex] VALUE -a|--all -j|--json".
     """
     num_runs = 3
     for _ in range(num_runs):
         helpers.execute_python(
             [self.script, self.input_file, self.output_file])
     db_log, _ = helpers.get_log(recipyenv.get_recipydb())
     unique_id = db_log["unique_id"]
     pattern = self.get_search(search_flag, unique_id)
     cmd = ["recipy", "search"]
     cmd.extend(pattern)
     cmd.append(all_flag)
     cmd.append(json_flag)
     _, stdout = helpers.execute(cmd, 0)
     assert len(stdout) > 0, "Expected stdout"
     json_logs = json.loads(" ".join(stdout))
     assert num_runs + 1 == len(json_logs),\
         "Unexpected number of JSON logs"