def test_init(self):
        syn = Mock()
        entity_id = 'syn123'
        path = '/tmp/foo/bar'
        child_ids = ['syn456', 'syn789']

        parent = _FolderSync(syn, 'syn987', '/tmp/foo', [entity_id], None)
        child = _FolderSync(syn, entity_id, path, child_ids, parent)
        assert syn == child._syn
        assert entity_id == child._entity_id
        assert path == child._path
        assert set(child_ids) == child._pending_ids
        assert parent == child._parent
    def _finished_test(self, path):
        syn = Mock()
        entity_id = 'syn123'
        child_ids = ['syn456']
        file = Mock()

        parent = _FolderSync(syn, 'syn987', path, [entity_id], None)
        child = _FolderSync(syn, entity_id, (path + '/bar') if path else None,
                            child_ids, parent)

        child.update(finished_id='syn456', files=[file])
        assert child._is_finished()
        assert parent._is_finished()
        parent.wait_until_finished()
        return child
    def test_set_exception(self):
        syn = Mock()
        path = '/tmp/foo'
        entity_id = 'syn123'
        child_ids = ['syn456']

        parent = _FolderSync(syn, 'syn987', path, [entity_id], None)
        child = _FolderSync(syn, entity_id, (path + '/bar') if path else None,
                            child_ids, parent)

        exception = ValueError('failed!')
        child.set_exception(exception)
        assert exception is child.get_exception()
        assert exception is parent.get_exception()
        assert child._is_finished()
        assert parent._is_finished()
    def test_update(self):
        syn = Mock()
        entity_id = 'syn123'
        path = '/tmp/foo/bar'
        child_ids = ['syn456', 'syn789']
        folder_sync = _FolderSync(syn, entity_id, path, child_ids, None)

        file = Mock()
        provenance = {'syn456': {'foo': 'bar'}}

        folder_sync.update(finished_id='syn456',
                           files=[file],
                           provenance=provenance)
        assert set(['syn789']) == folder_sync._pending_ids
        assert [file] == folder_sync._files
        assert provenance == folder_sync._provenance