예제 #1
0
 def test_add_movieSameID_throwsException(self):
     movie = Movie(1, 'a', '', '')
     movie_sameID = Movie(1, 'b', '', '')
     repository = Repository()
     repository.add(movie)
     with self.assertRaises(RepositoryError):
         repository.add(movie_sameID)
예제 #2
0
 def test_updateElement_with1emptyField_elementUpdated1fieldUnchanged(self):
     repository = Repository()
     movie = Movie(1, 'Frozen', 'Ice queen with magical powers',
                   'Animation')
     repository.add(movie)
     repository.update(movie, Movie(1, '', 'a', 'b'))
     expected_result = Movie(1, 'Frozen', 'a', 'b')
     self.assertTrue(repository.get_all()[0].identical(expected_result))
예제 #3
0
 def test_updateElement_withAllFields_elementUpdated(self):
     repository = Repository()
     movie = Movie(1, 'Frozen', 'Ice queen with magical powers',
                   'Animation')
     repository.add(movie)
     movieUpdate = Movie(1, '-', '-', '-')
     repository.update(movie, movieUpdate)
     self.assertTrue(repository.get_all()[0].identical(movieUpdate))
예제 #4
0
    def _loadFile(self):

        filepath = self._fileName
        file = open(filepath, "rb")

        if os.path.getsize(filepath) > 0:
            with open(filepath, "rb") as file:
                while True:
                    try:
                        _object = pickle.load(file)
                        Repository.add(self, _object)

                    except EOFError:
                        break

        file.close()
예제 #5
0
 def getLate(self):
     repoOfLateStudents=Repository()
     for i in range(len(self.__idlist)):
         studentID=self.__idlist[i]
         assignmentsOfStudent=self.__assignmentDict[studentID]
         #we look into the assignments of the student w/ studentID
         for j in range(len(assignmentsOfStudent)):
             assignmentFound=self.__repoAssignments.search(assignmentsOfStudent[j])
             deadline=assignmentFound.get_deadline()
             date=deadline.split(".")
             day=int(date[0])
             month=int(date[1])
             if self.checkLateDeadline(day,month)==True:
                 student=self.__repoStudents.search(studentID)
                 try:
                     repoOfLateStudents.add(student)
                 except ValueError:
                     pass
     return repoOfLateStudents
예제 #6
0
class TestsThirdFunctionality(unittest.TestCase):
    def setUp(self):
        unittest.TestCase.setUp(self)

    def initialize(self):
        self.__valid_movie = ValidMovie()
        self.__valid_client = ValidClient()
        self.__movies_repository = Repository()
        self.__clients_repository = Repository()
        self.__rentals_repository = Repository()
        undoStack = Stack()
        redoStack = Stack()
        self.__service_movies = ServiceMovies(self.__movies_repository,
                                              self.__valid_movie, undoStack,
                                              redoStack,
                                              self.__rentals_repository)
        self.__service_clients = ServiceClients(self.__clients_repository,
                                                self.__valid_client, undoStack,
                                                redoStack,
                                                self.__rentals_repository)

        self.__movies_repository.add(Movie(1, 'Frozen', 'Ice', 'Animation'))
        self.__movies_repository.add(
            Movie(2, 'Harry Potter', 'Wizard', 'Adventure'))
        self.__clients_repository.add(Client(1, 'John Doe'))
        self.__clients_repository.add(Client(2, 'Jane Doe'))

    def test_searchMovie_validKey_returnsMovies(self):
        self.initialize()
        found_movies = self.__service_movies.search_movie('otter')
        expected_result = Movie(2, 'Harry Potter', 'Wizard', 'Adventure')
        self.assertEqual(expected_result, found_movies[0])

    def test_searchClient_validKey_returnsClients(self):
        self.initialize()
        found_clients = self.__service_clients.search_client('doe')
        found_client1 = Client(1, 'John Doe')
        found_client2 = Client(2, 'Jane Doe')
        self.assertEqual(found_client1, found_clients[0])
        self.assertEqual(found_client2, found_clients[1])
예제 #7
0
class StudentTests(unittest.TestCase):
    def setUp(self):
        self.__student_repository = Repository()
        self.__student_repository.add(Student(1, "Test Student", 917))
        self.__student_repository.add(Student(2, "Student Test", 916))
        self.addValidInput = Student(3, "Le Student", 916)
        self.addInvalidInput = Student(1, "Le Student", "da")
        self.removeValidInput = Student(1, None, None)
        self.removeInvalidInput = Student(5, None, None)
        self.updateValidInput = Student(1, None, None)
        self.updateInvalidInput = Student(5, None, None)
        self.updateParameter = "New Student"

    def test__add_student__validInput__addsStudent(self):
        self.__student_repository.add(self.addValidInput)
        students = self.__student_repository.get_all_items()
        self.assertEqual(students, [
            Student(1, "Test Student", 917),
            Student(2, "Student Test", 916),
            Student(3, "Le Student", 916)
        ])

    def test__add_student__invalidInput__raisesError(self):
        try:
            self.__student_repository.add(self.addInvalidInput)
        except RepoError:
            pass
        self.assertRaises(RepoError)

    def test__remove_student__validInput__removesStudent(self):
        self.__student_repository.remove(self.removeValidInput)
        students = self.__student_repository.get_all_items()
        self.assertEqual(students, [Student(2, "Student Test", 916)])

    def test__remove_student__invalidInput__raisesError(self):
        try:
            self.__student_repository.remove(self.removeInvalidInput)
        except RepoError:
            pass
        self.assertRaises(RepoError)
예제 #8
0
class AssignmentTests(unittest.TestCase):
    def setUp(self):
        self.__assignment_repository = Repository()
        self.__assignment_repository.add(Assignment(1, "Test Assignment", 917))
        self.__assignment_repository.add(Assignment(2, "Assignment Test", 916))
        self.addValidInput = Assignment(3, "Le Assignment", 916)
        self.addInvalidInput = Assignment(1, "Le Assignment", "da")
        self.removeValidInput = Assignment(1, None, None)
        self.removeInvalidInput = Assignment(5, None, None)
        self.updateValidInput = Assignment(1, None, None)
        self.updateInvalidInput = Assignment(5, None, None)
        self.updateParameter = "New Assignment"

    def test__add_assignment__validInput__addsAssignment(self):
        self.__assignment_repository.add(self.addValidInput)
        assignments = self.__assignment_repository.get_all_items()
        self.assertEqual(assignments, [
            Assignment(1, "Test Assignment", 917),
            Assignment(2, "Assignment Test", 916),
            Assignment(3, "Le Assignment", 916)
        ])

    def test__add_assignment__invalidInput__raisesError(self):
        try:
            self.__assignment_repository.add(self.addInvalidInput)
        except RepoError:
            pass
        self.assertRaises(RepoError)

    def test__remove_assignment__validInput__removesAssignment(self):
        self.__assignment_repository.remove(self.removeValidInput)
        assignments = self.__assignment_repository.get_all_items()
        self.assertEqual(assignments, [Assignment(2, "Assignment Test", 916)])

    def test__remove_assignment__invalidInput__raisesError(self):
        try:
            self.__assignment_repository.remove(self.removeInvalidInput)
        except RepoError:
            pass
        self.assertRaises(RepoError)
예제 #9
0
 def test_add_newMovie_movieIsAdded(self):
     movie = Movie(1, 'a', 'a', 'a')
     repo = Repository()
     repo.add(movie)
     self.assertEqual(repo.size(), 1)
     self.assertEqual(repo.get_all()[repo.size() - 1], movie)
예제 #10
0
class TestsSecondFunctionality(unittest.TestCase):
    def setUp(self):
        unittest.TestCase.setUp(self)

    def initialize(self):
        undoStack = Stack()
        redoStack = Stack()
        self.__rental_validator = ValidRental()
        self.__movies_repository = Repository()
        self.__clients_repository = Repository()
        self.__rentals_repository = Repository()
        self.__service_rentals = ServiceRentals(self.__movies_repository,
                                                self.__clients_repository,
                                                self.__rentals_repository,
                                                self.__rental_validator,
                                                undoStack, redoStack)

        self.__movies_repository.add(Movie(1, 'Frozen', 'Ice', 'Animation'))
        self.__movies_repository.add(
            Movie(2, 'Harry Potter', 'Wizard', 'Adventure'))
        self.__clients_repository.add(Client(1, 'John Doe'))
        self.__clients_repository.add(Client(2, 'Jane Doe'))

        self.assertEqual(self.__service_rentals.get_number(), 0)

    def test_setters_rental_areSet(self):
        rental = Rental(1, 1, 1, Date(1, 1, 1), Date(2, 2, 2), Date(0, 0, 0))
        rental.set_clientId(2)
        self.assertEqual(rental.get_clientId(), 2)
        rental.set_movieId(2)
        self.assertEqual(rental.get_movieId(), 2)
        rental.set_rentalId(2)
        self.assertEqual(rental.get_rentalId(), 2)
        rental.set_rentDate(Date(2, 1, 1))
        self.assertEqual(rental.get_rentDate(), Date(2, 1, 1))
        rental.set_dueDate(Date(3, 3, 3))
        self.assertEqual(rental.get_dueDate(), Date(3, 3, 3))

    def test_str_rental_string(self):
        rental = Rental(1, 1, 1, Date(1, 1, 1), Date(2, 2, 2), Date(0, 0, 0))
        self.assertEqual(
            str(rental), "Rental ID: 1" + "\n" + "Movie ID: 1" + '\n' +
            "Client ID: 1" + '\n' + "   Rented:   1/1/1" + '\n' +
            "   Due date: 2/2/2" + '\n' + "   Returned: - \n")
        rental = Rental(1, 1, 1, Date(1, 1, 1), Date(2, 2, 2), Date(3, 3, 3))
        self.assertEqual(
            str(rental), "Rental ID: 1" + "\n" + "Movie ID: 1" + '\n' +
            "Client ID: 1" + '\n' + "   Rented:   1/1/1" + '\n' +
            "   Due date: 2/2/2" + '\n' + "   Returned: 3/3/3" + "\n")

    def test_identical_sameRentals_True(self):
        rental = Rental(1, 1, 1, Date(1, 1, 1), Date(2, 2, 2), Date(0, 0, 0))
        rental1 = Rental(1, 1, 1, Date(1, 1, 1), Date(2, 2, 2), Date(0, 0, 0))
        self.assertTrue(rental.identical(rental1))

    def test_daysRented_rental_returnsNrOfDays(self):
        rental = Rental(1, 1, 1, Date(1, 1, 1), Date(2, 2, 2), Date(4, 1, 1))
        self.assertEqual(rental.number_of_days_rented(), 4)

    def test_invalidDate(self):
        with self.assertRaises(DateError):
            d = Date(111, 111, 11)

    def test_getDate_invalidForm_ThrowsException(self):
        self.initialize()
        with self.assertRaises(DateError):
            self.__service_rentals.get_date('1234')

    def test_validateRental_validRental_none(self):
        self.initialize()
        rentals = self.__service_rentals.get_rentals()
        rental = Rental(1, 1, 1, Date(2, 1, 1), Date(2, 2, 2), Date(3, 3, 3))
        self.__rental_validator.validate_rental(rental, rentals)

    def test_validateRental_unavailableMovie_throwsException(self):
        self.initialize()
        self.__service_rentals.rent_movie(1, 1, 1, '1/1/1', '2/2/2')
        rentals = self.__service_rentals.get_rentals()
        rental = Rental(2, 1, 2, Date(2, 1, 1), Date(2, 2, 2), Date(3, 3, 3))
        with self.assertRaises(ValidationError):
            self.__rental_validator.validate_rental(rental, rentals)

    def test_validateRental_lateClient_throwsException(self):
        self.initialize()
        self.__service_rentals.rent_movie(1, 1, 1, '1/1/1', '2/2/1')
        rentals = self.__service_rentals.get_rentals()
        rental = Rental(2, 2, 1, Date(2, 1, 2), Date(2, 2, 2), Date(3, 3, 3))
        with self.assertRaises(ValidationError):
            self.__rental_validator.validate_rental(rental, rentals)

    def test_rent_validMovieAndClient_rentalIsCreated(self):
        self.initialize()
        self.__service_rentals.rent_movie(1, 1, 1, '1/1/2000', '1/1/2001')
        rental = Rental(1, 1, 1, Date(1, 1, 2000), Date(1, 1, 2001),
                        Date(0, 0, 0))
        self.assertEqual(self.__service_rentals.get_rentals()[0], rental)

    def test_rent_unavailableMovie_throwsException(self):
        self.initialize()
        self.__service_rentals.rent_movie(1, 1, 1, '1/1/2000', '1/1/2001')
        with self.assertRaises(RentingError):
            self.__service_rentals.rent_movie(2, 1, 2, '2/2/2000', '3/3/2000')

    def test_rent_clientPassedDueDate_throwsException(self):
        self.initialize()
        self.__service_rentals.rent_movie(1, 1, 1, '1/1/2000', '1/1/2001')
        with self.assertRaises(RentingError):
            self.__service_rentals.rent_movie(2, 2, 1, '2/1/2001', '2/2/2001')

    def test_rent_existingRentalId_throwsException(self):
        self.initialize()
        self.__service_rentals.rent_movie(1, 1, 1, '1/1/2000', '1/1/2001')
        with self.assertRaises(RepositoryError):
            self.__service_rentals.rent_movie(1, 2, 2, '2/1/2001', '2/2/2001')

    def test_rent_inexistentMovieClientId_throwsException(self):
        self.initialize()
        with self.assertRaises(RepositoryError):
            self.__service_rentals.rent_movie(1, 3, 2, '2/1/2001', '2/2/2001')

    def test_rent_timelineError_exception(self):
        self.initialize()
        with self.assertRaises(TimelineError):
            self.__service_rentals.rent_movie(1, 1, 1, '2/2/2', '1/1/1')

    def testRent(self):
        self.test_rent_validMovieAndClient_rentalIsCreated()
        self.test_rent_unavailableMovie_throwsException()
        self.test_rent_clientPassedDueDate_throwsException()
        self.test_rent_existingRentalId_throwsException()
        self.test_rent_inexistentMovieClientId_throwsException()

    def test_return_rentedMovie_returnDateIsAdded(self):
        self.initialize()
        self.__service_rentals.rent_movie(1, 1, 1, '1/1/2000', '1/1/2001')
        self.__service_rentals.return_movie(1, '2/2/2000')
        self.assertEqual(
            Date(2, 2, 2000),
            self.__rentals_repository.search(Rental(1, '', '', '', '',
                                                    '')).get_returnDate())

    def test_return_notrentedMovie_throwsException(self):
        self.initialize()
        with self.assertRaises(RepositoryError):
            self.__service_rentals.return_movie(1, '1/1/1')

    def test_return_returnedMovie_throwsException(self):
        self.initialize()
        self.__service_rentals.rent_movie(1, 1, 1, '1/1/2000', '1/1/2001')
        self.__service_rentals.return_movie(1, '2/2/2000')
        with self.assertRaises(RentingError):
            self.__service_rentals.return_movie(1, '9/9/9999')

    def test_return_timelineError_exception(self):
        self.initialize()
        self.__service_rentals.rent_movie(1, 1, 1, '1/1/2', '2/2/2')
        with self.assertRaises(TimelineError):
            self.__service_rentals.return_movie(1, '1/1/1')

    def testReturn(self):
        self.test_return_rentedMovie_returnDateIsAdded()
        self.test_return_notrentedMovie_throwsException()
        self.test_return_returnedMovie_throwsException()
예제 #11
0
 def test_remove_movie_isRemoved(self):
     repository = Repository()
     movie = Movie(1, '-', '-', '-')
     repository.add(movie)
     repository.remove(movie)
     self.assertEqual(repository.size(), 0)
예제 #12
0
class Services:
    def __init__(self):
        self.students = Repository(Repository.TYPE_STUDENTS)
        self.disciplines = Repository(Repository.TYPE_DISCIPLINES)
        self.grades = Repository(Repository.TYPE_GRADES)
        self.tracker = ActionTracker(self)

    def get_students_count(self):
        return self.students.get_size()

    def get_disciplines_count(self):
        return self.disciplines.get_size()

    def get_grades_count(self):
        return self.grades.get_size()

    def has_students(self):
        return self.students.is_not_empty()

    def has_disciplines(self):
        return self.disciplines.is_not_empty()

    def has_grades(self):
        return self.grades.is_not_empty()

    def is_empty(self):
        return self.students.is_empty() and self.disciplines.is_empty(
        ) and self.grades.is_empty()

    def clear(self):
        self.students.clear()
        self.disciplines.clear()
        self.grades.clear()

    def add_all(self, other, track=True):
        self.students.add_all(other.students)
        self.disciplines.add_all(other.disciplines)
        self.grades.add_all(other.grades)
        if track:
            self.tracker.add_action(ActionTracker.ADD_MULTIPLE, other)

    def is_student_id(self, sid):
        for s in self.students:
            if s.id == sid:
                return True
        return False

    def is_discipline_id(self, did):
        for d in self.disciplines:
            if d.id == did:
                return True
        return False

    def add_student(self, sid, name, track=True):
        student = Student(sid, name)
        self.students.add(student)
        if track:
            self.tracker.add_action(ActionTracker.ADD, student,
                                    ActionTracker.STUDENT)

    def add_discipline(self, did, name, track=True):
        discipline = Discipline(did, name)
        self.disciplines.add(discipline)
        if track:
            self.tracker.add_action(ActionTracker.ADD, discipline,
                                    ActionTracker.DISCIPLINE)

    def get_discipline(self, did):
        for d in self.disciplines:
            if d.id == did:
                return d
        raise Exception("Invalid discipline ID, no discipline found with ID " +
                        str(did))

    def get_student(self, sid):
        for s in self.students:
            if s.id == sid:
                return s
        raise Exception("Invalid student ID, no student found with ID " +
                        str(sid))

    def add_grade(self, discipline, student, value, track=True):
        if is_int(discipline):
            discipline = self.get_discipline(discipline)

        if is_int(student):
            student = self.get_student(student)

        grade = Grade(discipline, student, value)
        self.grades.add(grade)
        if track:
            self.tracker.add_action(ActionTracker.ADD, grade,
                                    ActionTracker.GRADE)

    def remove_student(self, sid, track=True):
        deleted = Group()
        student = self.get_student(sid)

        grades_copy = list(self.grades)
        for g in grades_copy:
            if g.student == student:
                deleted.grades.append(g)
                self.grades.remove(g)

        deleted.students.append(student)
        self.students.remove(student)
        if track:
            self.tracker.add_action(ActionTracker.REMOVE_MULTIPLE, deleted)

    def remove_discipline(self, did, track=True):
        deleted = Group()
        discipline = self.get_discipline(did)

        grades_copy = list(self.grades)
        for g in grades_copy:
            if g.discipline == discipline:
                deleted.grades.append(g)
                self.grades.remove(g)

        deleted.disciplines.append(discipline)
        self.disciplines.remove(discipline)
        if track:
            self.tracker.add_action(ActionTracker.REMOVE_MULTIPLE, deleted)

    def update_student(self, sid, name, track=True):
        student = self.get_student(sid)
        if track:
            self.tracker.add_action(ActionTracker.EDIT, copy.copy(student),
                                    ActionTracker.STUDENT)
        student.name = name

    def update_discipline(self, did, name, track=True):
        discipline = self.get_discipline(did)
        if track:
            self.tracker.add_action(ActionTracker.EDIT, copy.copy(discipline),
                                    ActionTracker.DISCIPLINE)
        discipline.name = name

    def search(self, keyword):
        search_group = Group()
        keyword = keyword.upper()

        for s in self.students:
            if keyword in str(s.id).upper() or keyword in s.name.upper():
                search_group.students.append(s)
        for d in self.disciplines:
            if keyword in str(d.id).upper() or keyword in d.name.upper():
                search_group.disciplines.append(d)

        return search_group

    def get_failing_students(self):
        students_with_grades = []

        for s in self.students:
            for d in self.disciplines:
                count = 0
                average = 0

                for g in self.grades:
                    if g.student == s and g.discipline == d:
                        count += 1
                        average += g.value

                if count == 0:
                    continue

                average /= count

                if average < 5:
                    students_with_grades.append(
                        Average(average, s.name, d.name))

        return students_with_grades

    def get_best_students(self):
        students_with_grades = []

        for s in self.students:
            total_count = 0
            total_average = 0

            for d in self.disciplines:
                count = 0
                average = 0

                for g in self.grades:
                    if g.student == s and g.discipline == d:
                        count += 1
                        average += g.value

                if count == 0:
                    continue

                total_count += 1
                total_average += average / count

            if total_count == 0:
                continue

            total_average /= total_count
            students_with_grades.append(
                Average(total_average, student_name=s.name))

        return students_with_grades

    def get_disciplines_with_grades(self):
        disciplines_with_grades = []

        for d in self.disciplines:
            count = 0
            average = 0

            for g in self.grades:
                if g.discipline == d:
                    count += 1
                    average += g.value

            if count == 0:
                continue

            average /= count
            disciplines_with_grades.append(
                Average(average, discipline_name=d.name))

        return disciplines_with_grades

    def undo(self):
        self.tracker.undo()

    def redo(self):
        self.tracker.redo()
예제 #13
0
 def add(self, _object):
     self._entities = []
     self._loadFile()
     Repository.add(self, _object)
     self._saveFile()
예제 #14
0
파일: stash.py 프로젝트: ton/stash
class Stash(object):
    """This class manages the collection of patches that have been stashed from
    various repositories. It provides functionality to list all available
    patches, to add, remove, and show individual patches, as well as applying
    stashed patches on a repository.
    """

    STASH_PATH = os.path.expanduser('~/.stash')

    def __init__(self, path):
        """To instantiantate a stash, provide a path that points to a location
        somewhere in a repository.
        """
        # Check if the patches path exists, and in case it does not, create it.
        if not os.path.exists(self.STASH_PATH):
            os.mkdir(self.STASH_PATH)

        self.repository = Repository(path)

        super(Stash, self).__init__()

    @classmethod
    def _get_patch_path(cls, patch_name):
        """Returns the absolute path for patch *patch_name*."""
        return os.path.join(cls.STASH_PATH, patch_name) if patch_name else None

    @classmethod
    def get_patches(cls):
        """Returns the names of all stashed patches."""
        return sorted(os.listdir(cls.STASH_PATH))

    @classmethod
    def remove_patch(cls, patch_name):
        """Removes patch *patch_name* from the stash (in case it exists).

        :raises: :py:exc:`~stash.exception.StashException` in case *patch_name* does not exist.
        """
        try:
            os.unlink(cls._get_patch_path(patch_name))
        except:
            raise StashException("patch '%s' does not exist" % patch_name)

    @classmethod
    def get_patch(cls, patch_name):
        """Returns the contents of the specified patch *patch_name*.

        :raises: :py:exc:`~stash.exception.StashException` in case *patch_name* does not exist.
        """
        try:
            return open(cls._get_patch_path(patch_name), 'r').read()
        except:
            raise StashException("patch '%s' does not exist" % patch_name)

    def apply_patch(self, patch_name):
        """Applies the patch *patch_name* on to the current working directory in
        case the patch exists. In case applying the patch was successful, the
        patch is automatically removed from the stash. Returns ``True`` in case
        applying the patch was successful, otherwise ``False`` is returned.

        :raises: :py:exc:`~stash.exception.StashException` in case *patch_name* does not exist.
        """
        if patch_name in self.get_patches():
            patch_path = self._get_patch_path(patch_name)

            # Apply the patch, and determine the files that have been added and
            # removed.
            pre_file_status = self.repository.status()
            patch_return_code = self.repository.apply_patch(patch_path)
            changed_file_status = self.repository.status().difference(pre_file_status)

            # Determine all files that have been added.
            for status, file_name in changed_file_status:
                if status == FileStatus.Added:
                    self.repository.add([file_name])
                elif status == FileStatus.Removed:
                    self.repository.remove([file_name])

            if patch_return_code == 0:
                # Applying the patch succeeded, remove stashed patch.
                os.unlink(patch_path)

            return patch_return_code == 0
        else:
            raise StashException("patch '%s' does not exist" % patch_name)

    def create_patch(self, patch_name):
        """Creates a patch based on the changes in the current repository. In
        case the specified patch *patch_name* already exists, ask the user to
        overwrite the patch. In case creating the patch was successful, all
        changes in the current repository are reverted. Returns ``True`` in case
        a patch was created, and ``False`` otherwise.

        :raises: :py:exc:`~stash.exception.StashException` in case *patch_name* already exists.
        """
        # Raise an exception in case the specified patch already exists.
        patch_path = self._get_patch_path(patch_name)
        if os.path.exists(patch_path):
            raise StashException("patch '%s' already exists" % patch_name)

        # Determine the contents for the new patch.
        patch = self.repository.diff()
        if patch != '':
            # Create the patch.
            patch_file = open(patch_path, 'wb')
            patch_file.write(patch.encode('utf-8'))
            patch_file.close()

            # Undo all changes in the repository, and determine which files have
            # been added or removed. Files that were added, need to be removed
            # again.
            pre_file_status = self.repository.status()
            self.repository.revert_all()
            changed_file_status = self.repository.status().difference(pre_file_status)

            # Remove all files that are created by the patch that is now being
            # stashed.
            for status, file_name in changed_file_status:
                if status == FileStatus.Added:
                    os.unlink(os.path.join(self.repository.root_path, file_name))

        # Return whether a non-empty patch was created.
        return patch != ''
예제 #15
0
 def add(self, element):
     self.__read_all_from_file()
     Repository.add(self, element)
     self.__write_all_to_file()