Exemplo n.º 1
0
def test_field_has_changed(test_row, test_column, test_value):
    our_model = EditableGitModel(REPOSITORY_NAME)
    our_model.populate()

    #    print "====================================== Before the write"
    #    for row in xrange(our_model.row_count()):
    #        print pretty_print_from_row(our_model, row)
    #    print "======================================================="

    index = Index(test_row, test_column)
    our_model.start_history_event()
    our_model.set_data(index, test_value)

    write_and_wait(our_model)

    new_model = GitModel(REPOSITORY_NAME)
    new_model.populate()
    new_model_value = new_model.data(index)
    #    print "======================================= After the write"
    #    for row in xrange(our_model.row_count()):
    #        print pretty_print_from_row(new_model, row)
    #    print "======================================================="

    if test_column in (1, 2):
        assert new_model_value[0] == test_value[0] and \
                new_model_value[1].tzname("") == test_value[1].tzname(""), \
                "The %s field wasn't changed correctly" % \
                AVAILABLE_CHOICES[test_column]
    else:
        assert new_model_value == test_value, \
                "The %s field wasn't changed correctly" % \
                    AVAILABLE_CHOICES[test_column]

    for row in xrange(our_model.row_count()):
        for column in xrange(1, our_model.column_count()):
            if (row == test_row and column == test_column):
                continue

            index = Index(row, column)

            our_value = our_model.data(index)
            new_value = new_model.data(index)
            if column in (1, 2):
                our_value, tz = our_value
                #    print our_value, tz.tzname(None)
                new_value, tz = new_value
            #    print new_value, tz.tzname(None)

            assert our_value == new_value, \
                    "Something else has change: (%d, %d)\ncolumn:%s\n" % \
                    (row, column, AVAILABLE_CHOICES[column]) + \
                    "%s\n%s\n%s\n" % \
                    (AVAILABLE_CHOICES,
                     pretty_print_from_row(our_model, row),
                     pretty_print_from_row(new_model, row)) + \
                    "%s // %s" % (our_value, new_value)
Exemplo n.º 2
0
    def set_current_branch(self, branch, force=False):
        """
            Sets the model's current branch.

            :param branch:
                The desired branch to modelize.
        """
        if self._changed_branch_once and not force:
            raise GfbiException("You shouldn't change the branch twice.")

        if self.is_fake_model():
            # This is the moment after we wrote the model, the model is getting
            # real (not fake).
            self.orig_model = GitModel(directory=self._directory)

        self.orig_model.set_current_branch(branch, force=force)
        self._modifications = {}

        GitModel.set_current_branch(self, branch, force=force)
Exemplo n.º 3
0
    def __init__(self, directory=".", fake_branch_name="", from_commits=False):
        """
            Initializes the model with the repository root directory.

            :param directory:
                Root directory of the git repository.
        """
        if fake_branch_name:
            # This is an empy gitModel that will be filled with data from
            # another model
            self.orig_model = None
        else:
            self.orig_model = GitModel(directory=directory)

        self.init_attributes()

        GitModel.__init__(self,
                          directory=directory,
                          fake_branch_name=fake_branch_name,
                          from_commits=from_commits)