def test_replace_same_folder(self):
        mkdir(p('dir1'))
        touch(p('dir1', 'a'))
        touch(p('dir1', 'b'))

        snapBefore = DirectorySnapshot(temp_dir)
        sleep(1)

        mv(p('dir1', 'a'), p('dir1', 'b'))

        snapAfter = DirectorySnapshot(temp_dir)
        changes = snapAfter - snapBefore

        expected = {
            'files_deleted': [
                p('dir1', 'b'),
            ],
            'files_moved': [
                (p('dir1', 'a'), p('dir1', 'b')),
            ],
            'dirs_modified': [
                p('dir1'),
            ]
        }

        self.verify(expected, changes)
    def test_replace_in_other_folder(self):
        mkdir(p('dir1'))
        mkdir(p('dir2'))
        touch(p('dir1', 'a'))
        touch(p('dir2', 'a'))

        snapBefore = DirectorySnapshot(temp_dir)
        sleep(1)

        # This case didn't work until the associated changes in disnapshot.py
        mv(p('dir1', 'a'), p('dir2', 'a'))

        snapAfter = DirectorySnapshot(temp_dir)
        changes = snapAfter - snapBefore

        expected = {
            'files_deleted': [
                p('dir2', 'a'),
            ],
            'files_moved': [
                (p('dir1', 'a'), p('dir2', 'a')),
            ],
            'dirs_modified': [
                p('dir1'),
                p('dir2'),
            ]
        }

        self.verify(expected, changes)
Exemple #3
0
    def test___init__(self):
        SLEEP_TIME = 0.4
        self.emitter.start()
        sleep(SLEEP_TIME)
        mkdir(p('project'))
        sleep(SLEEP_TIME)
        mkdir(p('project', 'blah'))
        sleep(SLEEP_TIME)
        touch(p('afile'))
        sleep(SLEEP_TIME)
        touch(p('fromfile'))
        sleep(SLEEP_TIME)
        mv(p('fromfile'), p('project', 'tofile'))
        sleep(SLEEP_TIME)
        touch(p('afile'))
        sleep(SLEEP_TIME)
        mv(p('project', 'blah'), p('project', 'boo'))
        sleep(SLEEP_TIME)
        rm(p('project'), recursive=True)
        sleep(SLEEP_TIME)
        rm(p('afile'))
        sleep(SLEEP_TIME)
        self.emitter.stop()

        # What we need here for the tests to pass is a collection type
        # that is:
        #   * unordered
        #   * non-unique
        # A multiset! Python's collections.Counter class seems appropriate.
        expected = set([
            DirModifiedEvent(p()),
            DirCreatedEvent(p('project')),
            DirModifiedEvent(p('project')),
            DirCreatedEvent(p('project', 'blah')),
            FileCreatedEvent(p('afile')),
            DirModifiedEvent(p()),
            FileCreatedEvent(p('fromfile')),
            DirModifiedEvent(p()),
            DirModifiedEvent(p()),
            FileMovedEvent(p('fromfile'), p('project', 'tofile')),
            FileModifiedEvent(p('afile')),
            DirModifiedEvent(p('project')),
            DirMovedEvent(p('project', 'blah'), p('project', 'boo')),
            DirModifiedEvent(p()),
            FileDeletedEvent(p('project', 'boo')),
            DirDeletedEvent(p('project', 'boo')),
            DirDeletedEvent(p('project')),
            DirModifiedEvent(p()),
            FileDeletedEvent(p('afile')),
        ])
        got = set()

        while True:
            try:
                event, _ = self.event_queue.get_nowait()
                got.add(event)
            except queue.Empty:
                break

        assert_equal(expected, got)
    def test___init__(self):
      SLEEP_TIME = 1
      self.emitter.start()
      sleep(SLEEP_TIME)
      mkdir(p('fromdir'))
      sleep(SLEEP_TIME)
      mv(p('fromdir'), p('todir'))
      sleep(SLEEP_TIME)
      self.emitter.stop()

      # What we need here for the tests to pass is a collection type
      # that is:
      #   * unordered
      #   * non-unique
      # A multiset! Python's collections.Counter class seems appropriate.
      expected = set([
        DirCreatedEvent(p('fromdir')),
        DirMovedEvent(p('fromdir'),p('todir')),
        ])
      got = set()

      while True:
        try:
          event, _ = self.event_queue.get_nowait()
          got.add(event)
        except queue.Empty:
          break

      print(got)
      self.assertEqual(expected, got)
    def test_mv_file_to_other_sibling_folder(self):
        mkdir(p("dir1"))
        mkdir(p("dir2"))
        touch(p("dir1", "a"))

        snapBefore = DirectorySnapshot(temp_dir)
        sleep(1)

        mv(p("dir1", "a"), p("dir2", "x"))

        snapAfter = DirectorySnapshot(temp_dir)
        changes = snapAfter - snapBefore

        expected = {"files_moved": [(p("dir1", "a"), p("dir2", "x"))], "dirs_modified": [p("dir1"), p("dir2")]}

        self.verify(expected, changes)
    def test_replace_same_folder(self):
        mkdir(p("dir1"))
        touch(p("dir1", "a"))
        touch(p("dir1", "b"))

        snapBefore = DirectorySnapshot(temp_dir)
        sleep(1)

        mv(p("dir1", "a"), p("dir1", "b"))

        snapAfter = DirectorySnapshot(temp_dir)
        changes = snapAfter - snapBefore

        expected = {"files_moved": [(p("dir1", "a"), p("dir1", "b"))], "dirs_modified": [p("dir1")]}

        self.verify(expected, changes)
    def test_replace_in_other_folder(self):
        mkdir(p("dir1"))
        mkdir(p("dir2"))
        touch(p("dir1", "a"))
        touch(p("dir2", "a"))

        snapBefore = DirectorySnapshot(temp_dir)
        sleep(1)

        # This case didn't work until the associated changes in disnapshot.py
        mv(p("dir1", "a"), p("dir2", "a"))

        snapAfter = DirectorySnapshot(temp_dir)
        changes = snapAfter - snapBefore

        expected = {"files_moved": [(p("dir1", "a"), p("dir2", "a"))], "dirs_modified": [p("dir1"), p("dir2")]}

        self.verify(expected, changes)
    def test_mv_file_to_other_sibling_folder(self):
        mkdir(p('dir1'))
        mkdir(p('dir2'))
        touch(p('dir1', 'a'))

        snapBefore = DirectorySnapshot(temp_dir)
        sleep(1)

        mv(p('dir1', 'a'), p('dir2', 'x'))

        snapAfter = DirectorySnapshot(temp_dir)
        changes = snapAfter - snapBefore

        expected = {
            'files_moved': [(p('dir1', 'a'), p('dir2', 'x')), ],
            'dirs_modified': [p('dir1'), p('dir2'), ]
        }

        self.verify(expected, changes)
    def test_replace_same_folder(self):
        mkdir(p('dir1'))
        touch(p('dir1', 'a'))
        touch(p('dir1', 'b'))

        snapBefore = DirectorySnapshot(temp_dir)
        sleep(1)

        mv(p('dir1', 'a'), p('dir1', 'b'))

        snapAfter = DirectorySnapshot(temp_dir)
        changes = snapAfter - snapBefore

        expected = {
            'files_moved': [(p('dir1', 'a'), p('dir1', 'b')), ],
            'dirs_modified': [p('dir1'), ]
        }

        self.verify(expected, changes)
  def test_replace_in_other_folder(self):
    mkdir(p('dir1'))
    mkdir(p('dir2'))
    touch(p('dir1', 'a'))
    touch(p('dir2', 'a'))

    snapBefore = DirectorySnapshot(temp_dir)
    sleep(1)

    # This case didn't work until the associated changes in disnapshot.py
    mv(p('dir1', 'a'), p('dir2', 'a'))

    snapAfter = DirectorySnapshot(temp_dir)
    changes = snapAfter - snapBefore

    expected = {
      'files_deleted': [ p('dir2', 'a'), ],
      'files_moved': [ (p('dir1', 'a'), p('dir2', 'a')), ],
      'dirs_modified': [ p('dir1'), p('dir2'), ]
    }

    self.verify(expected, changes)
    def test_mv_file_to_other_sibling_folder(self):
        mkdir(p('dir1'))
        mkdir(p('dir2'))
        touch(p('dir1', 'a'))

        snapBefore = DirectorySnapshot(temp_dir)
        sleep(1)

        mv(p('dir1', 'a'), p('dir2', 'x'))

        snapAfter = DirectorySnapshot(temp_dir)
        changes = snapAfter - snapBefore

        expected = {
            'files_moved': [
                (p('dir1', 'a'), p('dir2', 'x')),
            ],
            'dirs_modified': [
                p('dir1'),
                p('dir2'),
            ]
        }

        self.verify(expected, changes)
    def test_create_mv_a_b(self):

        touch(p('a'))

        self.start()

        self.fs(lambda: mv(p('a'), p('b')))

        expected = [
            FileMovedEvent(p('a'), p('b')),
            DirModifiedEvent(p()),
        ]

        got = self.collect_results()

        self.assertEqual(expected, got)
  def test_create_mv_a_b(self):

    touch(p('a'))

    self.start()

    self.fs(lambda: mv(p('a'), p('b')))

    expected = [
      FileMovedEvent(p('a'), p('b')),
      DirModifiedEvent(p()),
      ]

    got = self.collect_results()

    self.assertEqual(expected, got)
    def test___init__(self):
        SLEEP_TIME = 0.4
        self.emitter.start()
        sleep(SLEEP_TIME)
        mkdir(p('project'))
        sleep(SLEEP_TIME)
        mkdir(p('project', 'blah'))
        sleep(SLEEP_TIME)
        touch(p('afile'))
        sleep(SLEEP_TIME)
        touch(p('fromfile'))
        sleep(SLEEP_TIME)
        mv(p('fromfile'), p('project', 'tofile'))
        sleep(SLEEP_TIME)
        touch(p('afile'))
        sleep(SLEEP_TIME)
        mv(p('project', 'blah'), p('project', 'boo'))
        sleep(SLEEP_TIME)
        rm(p('project'), recursive=True)
        sleep(SLEEP_TIME)
        rm(p('afile'))
        sleep(SLEEP_TIME)
        self.emitter.stop()

        # What we need here for the tests to pass is a collection type
        # that is:
        #   * unordered
        #   * non-unique
        # A multiset! Python's collections.Counter class seems appropriate.
        expected = set([
            DirModifiedEvent(p()),
            DirCreatedEvent(p('project')),

            DirModifiedEvent(p('project')),
            DirCreatedEvent(p('project', 'blah')),

            FileCreatedEvent(p('afile')),
            DirModifiedEvent(p()),

            FileCreatedEvent(p('fromfile')),
            DirModifiedEvent(p()),

            DirModifiedEvent(p()),
            FileMovedEvent(p('fromfile'), p('project', 'tofile')),

            FileModifiedEvent(p('afile')),

            DirModifiedEvent(p('project')),
            DirMovedEvent(p('project', 'blah'), p('project', 'boo')),

            DirModifiedEvent(p()),
            FileDeletedEvent(p('project', 'boo')),
            DirDeletedEvent(p('project', 'boo')),
            DirDeletedEvent(p('project')),

            DirModifiedEvent(p()),
            FileDeletedEvent(p('afile')),

        ])
        got = set()

        while True:
            try:
                event, _ = self.event_queue.get_nowait()
                got.add(event)
            except queue.Empty:
                break

        self.assertEqual(expected, got)
    def test___init__(self):
        SLEEP_TIME = 0.4
        self.emitter.start()
        sleep(SLEEP_TIME)
        mkdir(p('project'))
        sleep(SLEEP_TIME)
        mkdir(p('project', 'blah'))
        sleep(SLEEP_TIME)
        touch(p('afile'))
        sleep(SLEEP_TIME)
        touch(p('fromfile'))
        sleep(SLEEP_TIME)
        mv(p('fromfile'), p('project', 'tofile'))
        sleep(SLEEP_TIME)
        touch(p('afile'))
        sleep(SLEEP_TIME)
        mv(p('project', 'blah'), p('project', 'boo'))
        sleep(SLEEP_TIME)
        rm(p('project'), recursive=True)
        sleep(SLEEP_TIME)
        rm(p('afile'))
        sleep(SLEEP_TIME)
        self.emitter.stop()

        # What we need here for the tests to pass is a collection type
        # that is:
        #   * unordered
        #   * non-unique
        # A multiset! Python's collections.Counter class seems appropriate.
        expected = set(
            [
                DirModifiedEvent(p()),
                DirCreatedEvent(p('project')),

                DirModifiedEvent(p('project')),
                DirCreatedEvent(p('project', 'blah')),

                FileCreatedEvent(p('afile')),
                DirModifiedEvent(p()),

                FileCreatedEvent(p('fromfile')),
                DirModifiedEvent(p()),

                DirModifiedEvent(p()),
                FileModifiedEvent(p('afile')),

                DirModifiedEvent(p('project')),

                DirModifiedEvent(p()),
                FileDeletedEvent(p('project', 'tofile')),
                DirDeletedEvent(p('project', 'boo')),
                DirDeletedEvent(p('project')),

                DirModifiedEvent(p()),
                FileDeletedEvent(p('afile')),
            ]
        )

        if sys.platform.startswith("win"):
            # On Windows depending on circumstances, a rename may turn into a Delete/Create
            expected.add(FileDeletedEvent(p('fromfile')))
            expected.add(FileCreatedEvent(p('project', 'tofile')))
            expected.add(DirCreatedEvent(p('project', 'boo')))
            expected.add(DirDeletedEvent(p('project', 'blah')))
        else:
            expected.add(FileMovedEvent(p('fromfile'), p('project', 'tofile')))
            expected.add(DirMovedEvent(p('project', 'blah'), p('project', 'boo')))

        got = set()
        while True:
            try:
                event, _ = self.event_queue.get_nowait()
                got.add(event)
            except queue.Empty:
                break

        self.assertEqual(expected, got)
Exemple #16
0
    def test___init__(self):
        SLEEP_TIME = 0.4
        self.emitter.start()
        sleep(SLEEP_TIME)
        mkdir(p('project'))
        sleep(SLEEP_TIME)
        mkdir(p('project', 'blah'))
        sleep(SLEEP_TIME)
        touch(p('afile'))
        sleep(SLEEP_TIME)
        touch(p('fromfile'))
        sleep(SLEEP_TIME)
        mv(p('fromfile'), p('project', 'tofile'))
        sleep(SLEEP_TIME)
        touch(p('afile'))
        sleep(SLEEP_TIME)
        mv(p('project', 'blah'), p('project', 'boo'))
        sleep(SLEEP_TIME)
        rm(p('project'), recursive=True)
        sleep(SLEEP_TIME)
        rm(p('afile'))
        sleep(SLEEP_TIME)
        self.emitter.stop()

        # What we need here for the tests to pass is a collection type
        # that is:
        #   * unordered
        #   * non-unique
        # A multiset! Python's collections.Counter class seems appropriate.
        expected = set([
            DirModifiedEvent(p()),
            DirCreatedEvent(p('project')),
            DirModifiedEvent(p('project')),
            DirCreatedEvent(p('project', 'blah')),
            FileCreatedEvent(p('afile')),
            DirModifiedEvent(p()),
            FileCreatedEvent(p('fromfile')),
            DirModifiedEvent(p()),
            DirModifiedEvent(p()),
            FileModifiedEvent(p('afile')),
            DirModifiedEvent(p('project')),
            DirModifiedEvent(p()),
            FileDeletedEvent(p('project', 'tofile')),
            DirDeletedEvent(p('project', 'boo')),
            DirDeletedEvent(p('project')),
            DirModifiedEvent(p()),
            FileDeletedEvent(p('afile')),
        ])

        if sys.platform.startswith("win"):
            # On Windows depending on circumstances, a rename may turn into a Delete/Create
            expected.add(FileDeletedEvent(p('fromfile')))
            expected.add(FileCreatedEvent(p('project', 'tofile')))
            expected.add(DirCreatedEvent(p('project', 'boo')))
            expected.add(DirDeletedEvent(p('project', 'blah')))
        else:
            expected.add(FileMovedEvent(p('fromfile'), p('project', 'tofile')))
            expected.add(
                DirMovedEvent(p('project', 'blah'), p('project', 'boo')))

        got = set()
        while True:
            try:
                event, _ = self.event_queue.get_nowait()
                got.add(event)
            except queue.Empty:
                break

        self.assertEqual(expected, got)