Пример #1
0
    def test_cache(self):
        """Ensure that _FactoryWrapper tries to import only once."""
        orig_date = datetime.date
        w = declarations._FactoryWrapper('datetime.date')
        self.assertEqual(None, w.factory)

        factory_class = w.get()
        self.assertEqual(orig_date, factory_class)

        try:
            # Modify original value
            datetime.date = None
            # Repeat import
            factory_class = w.get()
            self.assertEqual(orig_date, factory_class)

        finally:
            # IMPORTANT: restore attribute.
            datetime.date = orig_date
Пример #2
0
    def test_cache(self):
        """Ensure that _FactoryWrapper tries to import only once."""
        orig_date = datetime.date
        w = declarations._FactoryWrapper('datetime.date')
        self.assertEqual(None, w.factory)

        factory_class = w.get()
        self.assertEqual(orig_date, factory_class)

        try:
            # Modify original value
            datetime.date = None
            # Repeat import
            factory_class = w.get()
            self.assertEqual(orig_date, factory_class)

        finally:
            # IMPORTANT: restore attribute.
            datetime.date = orig_date
Пример #3
0
    def test_lazyness(self):
        f = declarations._FactoryWrapper('factory.declarations.Sequence')
        self.assertEqual(None, f.factory)

        factory_class = f.get()
        self.assertEqual(declarations.Sequence, factory_class)
Пример #4
0
 def test_path(self):
     w = declarations._FactoryWrapper('datetime.date')
     self.assertEqual(datetime.date, w.get())
Пример #5
0
 def test_class(self):
     w = declarations._FactoryWrapper(datetime.date)
     self.assertEqual(datetime.date, w.get())
Пример #6
0
 def test_invalid_path(self):
     with self.assertRaises(ValueError):
         declarations._FactoryWrapper('UnqualifiedSymbol')
     with self.assertRaises(ValueError):
         declarations._FactoryWrapper(42)
Пример #7
0
    def test_lazyness(self):
        f = declarations._FactoryWrapper('factory.declarations.Sequence')
        self.assertEqual(None, f.factory)

        factory_class = f.get()
        self.assertEqual(declarations.Sequence, factory_class)
Пример #8
0
 def test_path(self):
     w = declarations._FactoryWrapper('datetime.date')
     self.assertEqual(datetime.date, w.get())
Пример #9
0
 def test_class(self):
     w = declarations._FactoryWrapper(datetime.date)
     self.assertEqual(datetime.date, w.get())