# Path: axiom/scheduler.py
# class _SubSchedulerParentHook(Item):
#     schemaVersion = 4
#     typeName = 'axiom_subscheduler_parent_hook'
# 
#     subStore = reference(
#         doc="""
#         The L{SubStore} for which this scheduling hook exists.
#         """, reftype=SubStore)
# 
#     def run(self):
#         """
#         Tick our C{subStore}'s L{SubScheduler}.
#         """
#         IScheduler(self.subStore).tick()
# 
# 
#     def _schedule(self, when):
#         """
#         Ensure that this hook is scheduled to run at or before C{when}.
#         """
#         sched = IScheduler(self.store)
#         for scheduledAt in sched.scheduledTimes(self):
#             # https://github.com/twisted/epsilon/issues/38
#             if when._time < scheduledAt._time:
#                 sched.reschedule(self, scheduledAt, when)
#             break
#         else:
#             sched.schedule(self, when)
# 
# Path: axiom/substore.py
# class SubStore(Item):
# 
#     schemaVersion = 1
#     typeName = 'substore'
# 
#     storepath = path()
#     substore = inmemory()
# 
#     @classmethod
#     def createNew(cls, store, pathSegments):
#         """
#         Create a new SubStore, allocating a new file space for it.
#         """
#         if isinstance(pathSegments, six.string_types):
#             raise ValueError(
#                 'Received {!r} instead of a sequence'.format(pathSegments))
#         if store.dbdir is None:
#             self = cls(store=store, storepath=None)
#         else:
#             storepath = store.newDirectory(*pathSegments)
#             self = cls(store=store, storepath=storepath)
#         self.open()
#         self.close()
#         return self
# 
# 
#     def close(self):
#         self.substore.close()
#         del self.substore._openSubStore
#         del self.substore
# 
# 
#     def open(self, debug=None):
#         if hasattr(self, 'substore'):
#             return self.substore
#         else:
#             if debug is None:
#                 debug = self.store.debug
#             s = self.substore = self.createStore(debug, self.store.journalMode)
#             s._openSubStore = self # don't fall out of cache as long as the
#                                    # store is alive!
#             return s
# 
# 
#     def createStore(self, debug, journalMode=None):
#         """
#         Create the actual Store this Substore represents.
#         """
#         if self.storepath is None:
#             self.store._memorySubstores.append(self) # don't fall out of cache
#             if self.store.filesdir is None:
#                 filesdir = None
#             else:
#                 filesdir = (self.store.filesdir.child("_substore_files")
#                                                .child(str(self.storeID))
#                                                .path)
#             return Store(parent=self.store,
#                          filesdir=filesdir,
#                          idInParent=self.storeID,
#                          debug=debug,
#                          journalMode=journalMode)
#         else:
#             return Store(self.storepath.path,
#                          parent=self.store,
#                          idInParent=self.storeID,
#                          debug=debug,
#                          journalMode=journalMode)
# 
# 
#     def __conform__(self, interface):
#         """
#         I adapt my store object to whatever interface I am adapted to.  This
#         allows for avatar adaptation in L{axiom.userbase} to work properly
#         without having to know explicitly that all 'avatars' objects are
#         SubStore instances, since it is valid to have non-SubStore avatars,
#         which are simply adaptable to the cred interfaces they represent.
#         """
#         ifa = interface(self.open(debug=self.store.debug), None)
#         return ifa
# 
# 
#     def indirect(self, interface):
#         """
#         Like __conform__, I adapt my store to whatever interface I am asked to
#         produce a powerup for.  This allows for app stores to be installed as
#         powerups for their site stores directly, rather than having an
#         additional item type for each interface that we might wish to adapt to.
#         """
#         return interface(self)
# 
# Path: axiom/dependency.py
# class _DependencyConnector(Item):
#     """
#     I am a connector between installed items and their targets.
#     """
#     installee = reference(doc="The item installed.")
#     target = reference(doc="The item installed upon.")
#     explicitlyInstalled = boolean(doc="Whether this item was installed"
#                                   "explicitly (and thus whether or not it"
#                                   "should be automatically uninstalled when"
#                                   "nothing depends on it)")


from axiom.test.historic.stubloader import StubbedTest
from axiom.scheduler import _SubSchedulerParentHook
from axiom.substore import SubStore
from axiom.dependency import _DependencyConnector

"""
Test upgrading L{_SubSchedulerParentHook} from version 2 to 3.
"""




class SubSchedulerParentHookUpgradeTests(StubbedTest):
    """
    Test upgrading L{_SubSchedulerParentHook} from version 2 to 3.
    """
    def setUp(self):
        d = StubbedTest.setUp(self)
        def cbSetUp(ignored):
            self.hook = self.store.findUnique(_SubSchedulerParentHook)
        d.addCallback(cbSetUp)
        return d


    def test_attributesCopied(self):
        """
        The only attribute of L{_SubSchedulerParentHook} which still exists at
        the current version, version 4, C{subStore}, ought to have been
        copied over.
        """
        self.assertIdentical(

# Path: axiom/scheduler.py
# class _SubSchedulerParentHook(Item):
#     schemaVersion = 4
#     typeName = 'axiom_subscheduler_parent_hook'
# 
#     subStore = reference(
#         doc="""
#         The L{SubStore} for which this scheduling hook exists.
#         """, reftype=SubStore)
# 
#     def run(self):
#         """
#         Tick our C{subStore}'s L{SubScheduler}.
#         """
#         IScheduler(self.subStore).tick()
# 
# 
#     def _schedule(self, when):
#         """
#         Ensure that this hook is scheduled to run at or before C{when}.
#         """
#         sched = IScheduler(self.store)
#         for scheduledAt in sched.scheduledTimes(self):
#             # https://github.com/twisted/epsilon/issues/38
#             if when._time < scheduledAt._time:
#                 sched.reschedule(self, scheduledAt, when)
#             break
#         else:
#             sched.schedule(self, when)
# 
# Path: axiom/substore.py
# class SubStore(Item):
# 
#     schemaVersion = 1
#     typeName = 'substore'
# 
#     storepath = path()
#     substore = inmemory()
# 
#     @classmethod
#     def createNew(cls, store, pathSegments):
#         """
#         Create a new SubStore, allocating a new file space for it.
#         """
#         if isinstance(pathSegments, six.string_types):
#             raise ValueError(
#                 'Received {!r} instead of a sequence'.format(pathSegments))
#         if store.dbdir is None:
#             self = cls(store=store, storepath=None)
#         else:
#             storepath = store.newDirectory(*pathSegments)
#             self = cls(store=store, storepath=storepath)
#         self.open()
#         self.close()
#         return self
# 
# 
#     def close(self):
#         self.substore.close()
#         del self.substore._openSubStore
#         del self.substore
# 
# 
#     def open(self, debug=None):
#         if hasattr(self, 'substore'):
#             return self.substore
#         else:
#             if debug is None:
#                 debug = self.store.debug
#             s = self.substore = self.createStore(debug, self.store.journalMode)
#             s._openSubStore = self # don't fall out of cache as long as the
#                                    # store is alive!
#             return s
# 
# 
#     def createStore(self, debug, journalMode=None):
#         """
#         Create the actual Store this Substore represents.
#         """
#         if self.storepath is None:
#             self.store._memorySubstores.append(self) # don't fall out of cache
#             if self.store.filesdir is None:
#                 filesdir = None
#             else:
#                 filesdir = (self.store.filesdir.child("_substore_files")
#                                                .child(str(self.storeID))
#                                                .path)
#             return Store(parent=self.store,
#                          filesdir=filesdir,
#                          idInParent=self.storeID,
#                          debug=debug,
#                          journalMode=journalMode)
#         else:
#             return Store(self.storepath.path,
#                          parent=self.store,
#                          idInParent=self.storeID,
#                          debug=debug,
#                          journalMode=journalMode)
# 
# 
#     def __conform__(self, interface):
#         """
#         I adapt my store object to whatever interface I am adapted to.  This
#         allows for avatar adaptation in L{axiom.userbase} to work properly
#         without having to know explicitly that all 'avatars' objects are
#         SubStore instances, since it is valid to have non-SubStore avatars,
#         which are simply adaptable to the cred interfaces they represent.
#         """
#         ifa = interface(self.open(debug=self.store.debug), None)
#         return ifa
# 
# 
#     def indirect(self, interface):
#         """
#         Like __conform__, I adapt my store to whatever interface I am asked to
#         produce a powerup for.  This allows for app stores to be installed as
#         powerups for their site stores directly, rather than having an
#         additional item type for each interface that we might wish to adapt to.
#         """
#         return interface(self)
# 
# Path: axiom/dependency.py
# class _DependencyConnector(Item):
#     """
#     I am a connector between installed items and their targets.
#     """
#     installee = reference(doc="The item installed.")
#     target = reference(doc="The item installed upon.")
#     explicitlyInstalled = boolean(doc="Whether this item was installed"
#                                   "explicitly (and thus whether or not it"
#                                   "should be automatically uninstalled when"
#                                   "nothing depends on it)")


# Path: axiom/test/historic/test_parentHook2to3.py
from axiom.test.historic.stubloader import StubbedTest
from axiom.scheduler import _SubSchedulerParentHook
from axiom.substore import SubStore
from axiom.dependency import _DependencyConnector


"""
Test upgrading L{_SubSchedulerParentHook} from version 2 to 3.
"""




class SubSchedulerParentHookUpgradeTests(StubbedTest):
    """
    Test upgrading L{_SubSchedulerParentHook} from version 2 to 3.
    """
    def setUp(self):
        d = StubbedTest.setUp(self)
        def cbSetUp(ignored):
            self.hook = self.store.findUnique(_SubSchedulerParentHook)
        d.addCallback(cbSetUp)
        return d


    def test_attributesCopied(self):
        """
        The only attribute of L{_SubSchedulerParentHook} which still exists at
        the current version, version 4, C{subStore}, ought to have been
        copied over.
        """
        self.assertIdentical(

            self.hook.subStore, self.store.findUnique(SubStore))