示例#1
0
 def test_clear_observered_resources_for_filtered_observers(self):
     sample_file = self.project.root.create_file("myfile.txt")
     sample_observer = _SampleObserver()
     filtered = FilteredResourceObserver(sample_observer)
     self.project.add_observer(filtered)
     filtered.add_resource(sample_file)
     filtered.clear_resources()
     sample_file.write("1")
     self.assertEquals(0, sample_observer.change_count)
示例#2
0
 def test_removing_and_adding_resources_to_filtered_observer(self):
     my_file = self.project.root.create_file("my_file.txt")
     sample_observer = _SampleObserver()
     filtered_observer = FilteredResourceObserver(sample_observer)
     self.project.add_observer(filtered_observer)
     my_file.write("1")
     self.assertEquals(0, sample_observer.change_count)
     filtered_observer.add_resource(my_file)
     my_file.write("2")
     self.assertEquals(1, sample_observer.change_count)
     filtered_observer.remove_resource(my_file)
     my_file.write("3")
     self.assertEquals(1, sample_observer.change_count)
示例#3
0
 def test_resource_change_observer_for_folders(self):
     root_folder = self.project.root
     my_folder = root_folder.create_folder('my_folder')
     my_folder_observer = _SampleObserver()
     root_folder_observer = _SampleObserver()
     self.project.add_observer(
         FilteredResourceObserver(my_folder_observer, [my_folder]))
     self.project.add_observer(
         FilteredResourceObserver(root_folder_observer, [root_folder]))
     my_file = my_folder.create_file('my_file.txt')
     self.assertEquals(1, my_folder_observer.change_count)
     my_file.move('another_file.txt')
     self.assertEquals(2, my_folder_observer.change_count)
     self.assertEquals(1, root_folder_observer.change_count)
     self.project.get_resource('another_file.txt').remove()
     self.assertEquals(2, my_folder_observer.change_count)
     self.assertEquals(2, root_folder_observer.change_count)
示例#4
0
 def test_moving_and_being_interested_about_a_folder_and_a_child(self):
     my_folder = self.project.root.create_folder('my_folder')
     my_file = my_folder.create_file('my_file.txt')
     sample_observer = _SampleObserver()
     filtered_observer = FilteredResourceObserver(sample_observer,
                                                  [my_folder, my_file])
     self.project.add_observer(filtered_observer)
     my_folder.move('new_folder')
     self.assertEquals(2, sample_observer.change_count)
示例#5
0
 def test_revalidating_files_and_no_changes2(self):
     root = self.project.root
     my_file = root.create_file('my_file.txt')
     sample_observer = _SampleObserver()
     self.project.add_observer(
         FilteredResourceObserver(sample_observer, [my_file]))
     self.project.validate(root)
     self.assertEquals(None, sample_observer.last_moved)
     self.assertEquals(0, sample_observer.change_count)
示例#6
0
 def test_resource_change_observer_after_removal(self):
     sample_file = self.project.root.create_file('my_file.txt')
     sample_file.write('text')
     sample_observer = _SampleObserver()
     self.project.add_observer(
         FilteredResourceObserver(sample_observer, [sample_file]))
     sample_file.remove()
     self.assertEquals(1, sample_observer.change_count)
     self.assertEquals(sample_file, sample_observer.last_removed)
示例#7
0
 def test_validating_when_created(self):
     root = self.project.root
     my_file = self.project.get_file('my_file.txt')
     sample_observer = _SampleObserver()
     self.project.add_observer(
         FilteredResourceObserver(sample_observer, [my_file]))
     open(my_file.real_path, 'w').close()
     self.project.validate(root)
     self.assertEquals(my_file, sample_observer.last_created)
     self.assertEquals(1, sample_observer.change_count)
示例#8
0
 def test_revalidating_files(self):
     root = self.project.root
     my_file = root.create_file('my_file.txt')
     sample_observer = _SampleObserver()
     self.project.add_observer(
         FilteredResourceObserver(sample_observer, [my_file]))
     os.remove(my_file.real_path)
     self.project.validate(root)
     self.assertEquals(my_file, sample_observer.last_removed)
     self.assertEquals(1, sample_observer.change_count)
示例#9
0
 def test_revalidating_folders(self):
     root = self.project.root
     my_folder = root.create_folder('myfolder')
     my_file = my_folder.create_file('myfile.txt')  # noqa
     sample_observer = _SampleObserver()
     self.project.add_observer(
         FilteredResourceObserver(sample_observer, [my_folder]))
     testutils.remove_recursively(my_folder.real_path)
     self.project.validate(root)
     self.assertEquals(my_folder, sample_observer.last_removed)
     self.assertEquals(1, sample_observer.change_count)
示例#10
0
 def test_validation_and_changing_files(self):
     my_file = self.project.root.create_file('my_file.txt')
     sample_observer = _SampleObserver()
     timekeeper = _MockChangeIndicator()
     filtered_observer = FilteredResourceObserver(sample_observer, [my_file],
                                                  timekeeper=timekeeper)
     self.project.add_observer(filtered_observer)
     self._write_file(my_file.real_path)
     timekeeper.set_indicator(my_file, 1)
     self.project.validate(self.project.root)
     self.assertEquals(1, sample_observer.change_count)
示例#11
0
 def test_changes_and_adding_resources(self):
     root = self.project.root  # noqa
     file1 = self.project.get_file('file1.txt')
     file2 = self.project.get_file('file2.txt')
     file1.create()
     sample_observer = _SampleObserver()
     self.project.add_observer(
         FilteredResourceObserver(sample_observer, [file1, file2]))
     file1.move(file2.path)
     self.assertEquals(2, sample_observer.change_count)
     self.assertEquals(file2, sample_observer.last_created)
     self.assertEquals((file1, file2), sample_observer.last_moved)
示例#12
0
 def test_not_reporting_multiple_changes_to_folders(self):
     root = self.project.root
     file1 = root.create_file('file1.txt')
     file2 = root.create_file('file2.txt')
     sample_observer = _SampleObserver()
     self.project.add_observer(
         FilteredResourceObserver(sample_observer, [root, file1, file2]))
     os.remove(file1.real_path)
     os.remove(file2.real_path)
     self.assertEquals(0, sample_observer.change_count)
     self.project.validate(self.project.root)
     self.assertEquals(3, sample_observer.change_count)
示例#13
0
 def test_validation_and_changing_files2(self):
     my_file = self.project.root.create_file("my_file.txt")
     sample_observer = _SampleObserver()
     timekeeper = _MockChangeIndicator()
     self.project.add_observer(
         FilteredResourceObserver(sample_observer, [my_file],
                                  timekeeper=timekeeper))
     timekeeper.set_indicator(my_file, 1)
     my_file.write("hey")
     self.assertEqual(1, sample_observer.change_count)
     self.project.validate(self.project.root)
     self.assertEqual(1, sample_observer.change_count)
示例#14
0
 def test_clear_observered_resources_for_filtered_observers(self):
     sample_file = self.project.root.create_file('myfile.txt')
     sample_observer = _SampleObserver()
     filtered = FilteredResourceObserver(sample_observer)
     self.project.add_observer(filtered)
     filtered.add_resource(sample_file)
     filtered.clear_resources()
     sample_file.write('1')
     self.assertEquals(0, sample_observer.change_count)
示例#15
0
 def test_removing_and_adding_resources_to_filtered_observer(self):
     my_file = self.project.root.create_file('my_file.txt')
     sample_observer = _SampleObserver()
     filtered_observer = FilteredResourceObserver(sample_observer)
     self.project.add_observer(filtered_observer)
     my_file.write('1')
     self.assertEquals(0, sample_observer.change_count)
     filtered_observer.add_resource(my_file)
     my_file.write('2')
     self.assertEquals(1, sample_observer.change_count)
     filtered_observer.remove_resource(my_file)
     my_file.write('3')
     self.assertEquals(1, sample_observer.change_count)