def test_changset_contains_is_true_for_items_in_the_set(self, ): ## We test this two ways to be sure self.assertIn(mut.Change(mut.ChangeType.ADD_FILE, "add"), self.out) self.assertTrue(mut.Change(mut.ChangeType.ADD_FILE, "add") in self.out) self.assertIn(mut.Change(mut.ChangeType.REMOVE_FILE, "remove"), self.out) self.assertTrue( mut.Change(mut.ChangeType.REMOVE_FILE, "remove") in self.out)
def test_adding_a_remove__of_an_already_added_file_to_a_changet_removes_the_remove_but_leaves_anythingelse( self, ): self.out.add(mut.Change(mut.ChangeType.REMOVE_FILE, "add")) self.assertNotIn(mut.Change(mut.ChangeType.ADD_FILE, "add"), self.out) self.assertIn(mut.Change(mut.ChangeType.REMOVE_FILE, "add"), self.out) self.assertIn(mut.Change(mut.ChangeType.REMOVE_FILE, "remove"), self.out) #Also checked quiet in unset; self.assertEqual(self.out.anyadded.set_result.call_count, self.start_len + 1)
def test_adding_a_remove__of_an_already_removed_file_to_a_changeset_make_no_difference( self, ): cur = len(self.out) self.out.add(mut.Change(mut.ChangeType.REMOVE_FILE, "remove")) self.assertEqual(len(self.out), cur) self.assertEqual(self.out.anyadded.set_result.call_count, self.start_len)
def test_when_enqueue_change_call_extends_the_delay(self, ): change = mut.Change(mut.ChangeType.ADD_FILE, "path/file") with unittest.mock.patch.object(mut, 'extend_quiet_delay' , return_value = unittest.mock.sentinel.QUIET) as ag, \ unittest.mock.patch.object(mut.changes, 'add' , return_value = unittest.mock.sentinel.QUIET) as icsa,\ unittest.mock.patch.object(mut, 'event2change' , return_value = change) as ice2c: mut.enqueue_change(1, 2, 3, 4) ag.assert_called_once_with()
def test_when_enqueue_change_call_enquenue_the_change_by_covnert_it_and_adding_it( self, ): change = mut.Change(mut.ChangeType.ADD_FILE, "path/file") mut.rotate_changes() with unittest.mock.patch.object(mut, 'extend_quiet_delay' , return_value = unittest.mock.sentinel.QUIET) as ag, \ unittest.mock.patch.object(mut.changes, 'add' , return_value = unittest.mock.sentinel.QUIET) as icsa,\ unittest.mock.patch.object(mut, 'event2change' , return_value = change) as ice2c: mut.enqueue_change(1, 2, 3, 4) ice2c.assert_called_once_with(1, 2, 3, 4) icsa.assert_called_once_with(change)
def setUp(self, ): self.out = mut.ChangeSet() self.out.anyadded = unittest.mock.MagicMock() self.out.add(mut.Change(mut.ChangeType.ADD_FILE, "add")) self.out.add(mut.Change(mut.ChangeType.REMOVE_FILE, "remove")) self.start_len = 2