Exemplo n.º 1
0
def test1(done):
    data = Data(test_wb_name, ws_name)

    # write to column b
    expected_outcome = [
        "thedinner", "cool", "me", "tester", "please", "work", "im", "begging",
        'you'
    ]

    # try to update the cells make sure to catch all errors
    try:
        data.update_all_cells_in_column("B", expected_outcome)
    except Exception as e:
        raise AssertionError(str(e))

    # read column b make sure that you get the expected outcome
    outcome = data.return_column_as_list("B")
    msg = str(outcome[0:9]) + " was not equal to " + str(expected_outcome)
    assert outcome[0:9] == expected_outcome, msg

    # write to column b with some none values
    new_cells = [
        'does', 'none', 'none', 'none', 'none', 'none', 'none', 'none', 'work?'
    ]
    expected_outcome = [
        "does", "cool", "me", "tester", "please", "work", "im", "begging",
        'work?'
    ]

    # try to update the cells make sure to catch all errors
    try:
        data.update_all_cells_in_column("B", new_cells)
    except Exception as e:
        raise AssertionError(str(e))

    # read column b make sure that you get the expected outcome
    outcome = data.return_column_as_list("B")
    msg = str(outcome)[0:9] + " was not equal to " + str(expected_outcome)
    assert outcome[0:9] == expected_outcome, msg

    # reset column b to empty
    empty_list = ["", "", "", "", "", "", "", "", "",
                  ""]  #TODO make this more robust
    try:
        data.update_all_cells_in_column('B', empty_list)
    except Exception as e:
        raise AssertionError(str(e))

    # read column b assert that its empty
    outcome = data.return_column_as_list("B")
    msg = str(outcome) + " was not equal to " + str(empty_list)
    assert outcome == empty_list, msg

    done(
        "Series of reads and writes to excel file. The reads make sure that the writes actually worked."
    )
Exemplo n.º 2
0
def update_all_cells_in_column_throws(done):
    # create instance of data class
    data = Data(test_wb_name, ws_name)

    # list of all invalid inputs
    invalid_inputs = [
        "a",
        "b",
        "c",
        "d",
        "e",
        "f",
        "g",
        "h",
        "i",
        "j",
        "k",
        "l",
        "m",
        "n",
        "o",
        "p",
        "q",
        "r",
        "s",
        "t",
        "u",
        "v",
        "w",
        "x",
        "y",
        "z",
        "1",
        "2",
        "3",
        "4",
        "5",
        "6",
        "7",
        "8",
        1,
        2,
        3,
        243,
        "9",
        "AB",
        "AA",
        "11",
        "aa",
        "#",
        "$",
        "##A",
        "AS",
    ]
    for invalid_input in invalid_inputs:
        try:
            data.update_all_cells_in_column(invalid_input, ["tester"])
            raise AssertionError(
                "update_all_cells_in_column did not throw (it should have) when given input: "
                + str(invalid_input))
        except Exception as e:
            # it will catch the Assertion error
            msg = "update_all_cells_in_column did not throw (it should have) when given input: " + str(
                invalid_input)
            if str(e) == msg:
                raise AssertionError(
                    "update_all_cells_in_column did not throw (it should have) when given input: "
                    + str(invalid_input))
    done(
        "update_all_cells_in_column should throw if it is passed anything but a non-capital letter"
    )
Exemplo n.º 3
0
def update_all_cells_in_column_throws_param2(done):
    # create instance of data class
    data = Data(test_wb_name, ws_name)

    # list of all invalid inputs
    long_list = [
        "im long", "im long", "im long", "im long", "im long", "im long",
        "im long", "im long", "im long", "im long", "im long", "im long",
        "im long", "im long", "im long", "im long", "im long", "im long",
        "im long", "im long", "im long", "im long", "im long", "im long",
        "im long", "im long", "im long", "im long", "im long", "im long",
        "im long", "im long", "im long", "im long", "im long", "im long",
        "im long", "im long", "im long", "im long", "im long", "im long",
        "im long", "im long", "im long", "im long", "im long", "im long",
        "im long", "im long", "im long", "im long", "im long", "im long",
        "im long", "im long", "im long", "im long", "im long", "im long",
        "im long", "im long", "im long", "im long", "im long", "im long",
        "im long", "im long", "im long", "im long", "im long", "im long",
        "im long", "im long", "im long", "im long", "im long", "im long",
        "im long", "im long", "im long", "im long", "im long", "im long",
        "im long", "im long", "im long", "im long", "im long", "im long",
        "im long", "im long", "im long", "im long", "im long", "im long",
        "im long", "im long", "im long", "im long"
    ]
    invalid_inputs = [
        long_list,
        [],
        "a",
        "b",
        1,
        2,
        6,
        243,
        "c",
        "d",
        "e",
        "f",
        "g",
        "h",
        "i",
        "j",
        "k",
        "l",
        "m",
        "n",
        "o",
        "p",
        "q",
        "r",
        "s",
        "t",
        "u",
        "v",
        "w",
        "x",
        "y",
        "z",
        "1",
        "2",
        "3",
        "4",
        "5",
        "6",
        "7",
        "8",
        "9",
        "AB",
        "AA",
        "11",
        "aa",
        "#",
        "$",
        "##A",
        "AS",
    ]
    for invalid_input in invalid_inputs:
        try:
            data.update_all_cells_in_column('A', invalid_input)
            raise AssertionError(
                "update_all_cells_in_column did not throw (it should have) when given input: "
                + str(invalid_input))
        except Exception as e:
            # it will catch the Assertion error
            msg = "update_all_cells_in_column did not throw (it should have) when given input: " + str(
                invalid_input)
            if str(e) == msg:
                raise AssertionError(
                    "update_all_cells_in_column did not throw (it should have) when given input: "
                    + str(invalid_input))
    done(
        "update_all_cells_in_column should throw if the second argument is: empty list, not a list, very long list"
    )
Exemplo n.º 4
0
class Replacer():
    def __init__(self, wb_name, ws_name):
        self.iv = "O"
        self.dv = "X"
        self.data = Data(wb_name, ws_name)
        self.new_dv_list = []
        self.empty_char = 's'

    def strip_all_elements(self, untrimmed_list):
        """strip all elements of a list"""
        for x in range(len(untrimmed_list)):
            untrimmed_list[x] = untrimmed_list[x].strip()
        return untrimmed_list

    def replace_iv_dv(self):
        """if iv in dv, remove it from dv"""
        # get iv and dv columns
        iv_list = self.data.return_column_as_list(self.iv)
        dv_list = self.data.return_column_as_list(self.dv)

        # sanity check that both lists are the same
        if len(iv_list) == len(dv_list):
            # loop through iv's
            for x in range(len(iv_list)):
                # define what cells we are working with
                iv_cell = str(iv_list[x])
                dv_cell = str(dv_list[x])

                # if the cell is empty, don't even bother comparing
                if iv_cell.strip() != "":
                    iv_cell_authors_list = self.strip_all_elements(
                        iv_cell.split(","))
                    dv_cell_authors_list = self.strip_all_elements(
                        dv_cell.split(","))

                    # loop through the authors
                    for untrimmed_iv_author in iv_cell_authors_list:
                        trimmed_iv_author = untrimmed_iv_author.split(
                            "(")[0].strip()
                        # loop through the dv comparing the trimmed author to the dv's authors
                        for untrimmed_dv_author in range(
                                len(dv_cell_authors_list)):
                            if untrimmed_dv_author >= len(
                                    dv_cell_authors_list):
                                break
                            untrimmed_dv_author = dv_cell_authors_list[
                                untrimmed_dv_author]
                            trimmed_dv_author = untrimmed_dv_author.split(
                                "(")[0].strip()
                            if trimmed_dv_author.lower(
                            ) == trimmed_iv_author.lower():
                                while True:
                                    try:
                                        dv_cell_authors_list.remove(
                                            untrimmed_dv_author)
                                    except ValueError:
                                        break
                    if len(dv_cell_authors_list) != 0 and len(
                            dv_cell_authors_list) != 1:
                        new_dv_cell_str = ", ".join(dv_cell_authors_list)
                        if new_dv_cell_str == dv_cell:
                            self.new_dv_list.append("none")
                        else:
                            self.new_dv_list.append(new_dv_cell_str.strip())
                    elif len(dv_cell_authors_list) == 0:
                        self.new_dv_list.append(self.empty_char)
                    elif len(dv_cell_authors_list) == 1:
                        if dv_cell_authors_list[0].strip() == '':
                            self.new_dv_list.append(self.empty_char)
                        else:
                            self.new_dv_list.append(
                                dv_cell_authors_list[0].strip())
                else:
                    self.new_dv_list.append("none")
            # update the cells with their new values
            self.data.update_all_cells_in_column(self.dv, self.new_dv_list)

            # log the changes to the file system
            log = Log_Maker(self.dv, dv_list, self.new_dv_list)
            log.both()

            return self.new_dv_list
        else:
            raise Exception("column " + self.dv +
                            " was not equal in length to column " + self.iv)