Ejemplo n.º 1
0
    def test_mssqlcliclient_multiple_merge(client_with_db):
        """
        Tests query with multiple merges. Requires creation of temp db.
        """
        file_input, _ = get_io_paths('multiple_merge.txt')
        query_input = get_file_contents(file_input)

        for rows, _, status, _, is_error in client_with_db.execute_query(query_input):
            if is_error:
                raise AssertionError("Query execution failed: {}".format(status))
            assert () == rows
    def test_output_file(self, query_str, test_file, tmp_filepath):
        """ Tests -o (and ensures file overwrite works) """
        file_input, file_baseline = get_io_paths(test_file)
        output_baseline = get_file_contents(file_baseline)
        query_str = '-Q "{}"'.format(query_str)     # append -Q for non-interactive call

        # test with -Q
        output_query_for_Q = self.execute_query_via_subprocess(query_str, output_file=tmp_filepath)
        assert output_query_for_Q == output_baseline

        # test with -i
        output_query_for_i = self.execute_query_via_subprocess("-i %s" % file_input,
                                                               output_file=tmp_filepath)
        assert output_query_for_i == output_baseline
    def test_query(self, query_str, test_file):
        """ Tests query outputs to command-line, ensuring -Q and -i produce
        the same results. """
        file_input, file_baseline = get_io_paths(test_file)
        output_baseline = get_file_contents(file_baseline)
        query_str = '-Q "{}"'.format(query_str)     # append -Q for non-interactive call

        # test with -Q
        output_query_for_Q = self.execute_query_via_subprocess(query_str)
        assert output_query_for_Q == output_baseline

        # test with -i
        output_query_for_i = self.execute_query_via_subprocess("-i %s" % file_input)
        assert output_query_for_i == output_baseline
    def test_long_query(tmp_filepath):
        """ Output large query using Python class instance. """
        query_str = "SELECT * FROM STRING_SPLIT(REPLICATE(CAST('X,' AS VARCHAR(MAX)), 1024), ',')"
        try:
            mssqlcli = create_mssql_cli(interactive_mode=False, output_file=tmp_filepath)
            output_query = '\n'.join(mssqlcli.execute_query(query_str))
            file_baseline = get_io_paths('big.txt')[1]
            output_baseline = get_file_contents(file_baseline)
            assert output_query == output_baseline

            # test output to file
            output_query_from_file = get_file_contents(tmp_filepath)
            assert output_query_from_file == output_baseline
        finally:
            shutdown(mssqlcli)
    def test_multiple_merge(self):
        """
        Tests query with multiple merges. Requires creation of temp db.
        """
        try:
            # create temporary db
            db_name = create_test_db()

            file_input, file_baseline = get_io_paths('multiple_merge.txt')
            text_baseline = get_file_contents(file_baseline)

            # test with -i
            output_query = self.execute_query_via_subprocess("-i {} -d {}"\
                                                             .format(file_input, db_name))
            assert output_query == text_baseline
        finally:
            clean_up_test_db(db_name)
Ejemplo n.º 6
0
 def test_query(query_str, test_file, mssqlcli):
     _, file_baseline = get_io_paths(test_file)
     output_baseline = get_file_contents(file_baseline)
     output_query = '\n'.join(mssqlcli.execute_query(query_str)).replace(
         '\r', '')
     assert output_query == output_baseline