Exemplo n.º 1
0
    def test_load_model(self):
        """load model from dotted name"""
        model_path = os.path.join(self.temp_usable_dir, 'test_load_model.py')

        f = open(model_path, 'w')
        f.write("class FakeFloat(int): pass")
        f.close()

        try:
            # py 2.4 compatability :-/
            cw = catch_warnings(record=True)
            w = cw.__enter__()

            warnings.simplefilter("always")

            # deprecated spelling
            FakeFloat = load_model('test_load_model.FakeFloat')
            self.assert_(isinstance(FakeFloat(), int))

            self.assertEqual(len(w), 1)
            self.assertTrue(
                issubclass(w[-1].category, MigrateDeprecationWarning))
            self.assertEqual(
                'model should be in form of module.model:User '
                'and not module.model.User', str(w[-1].message))

        finally:
            cw.__exit__()

        FakeFloat = load_model('test_load_model:FakeFloat')
        self.assert_(isinstance(FakeFloat(), int))

        FakeFloat = load_model(FakeFloat)
        self.assert_(isinstance(FakeFloat(), int))
Exemplo n.º 2
0
    def test_load_model(self):
        """load model from dotted name"""
        model_path = os.path.join(self.temp_usable_dir, 'test_load_model.py')

        f = open(model_path, 'w')
        f.write("class FakeFloat(int): pass")
        f.close()

        try:
            # py 2.4 compatability :-/
            cw = catch_warnings(record=True)
            w = cw.__enter__()

            warnings.simplefilter("always")

            # deprecated spelling
            FakeFloat = load_model('test_load_model.FakeFloat')
            self.assertTrue(isinstance(FakeFloat(), int))

            self.assertEqual(len(w),1)
            self.assertTrue(issubclass(w[-1].category,
                                       MigrateDeprecationWarning))
            self.assertEqual(
                'model should be in form of module.model:User '
                'and not module.model.User',
                str(w[-1].message))

        finally:
            cw.__exit__()

        FakeFloat = load_model('test_load_model:FakeFloat')
        self.assertTrue(isinstance(FakeFloat(), int))

        FakeFloat = load_model(FakeFloat)
        self.assertTrue(isinstance(FakeFloat(), int))
Exemplo n.º 3
0
    def test_construct_engine(self):
        """Construct engine the smart way"""
        url = 'sqlite://'

        engine = construct_engine(url)
        self.assert_(engine.name == 'sqlite')

        # keyword arg
        engine = construct_engine(url, engine_arg_encoding=True)
        self.assertTrue(engine.dialect.encoding)

        # dict
        engine = construct_engine(url, engine_dict={'encoding': True})
        self.assertTrue(engine.dialect.encoding)

        # engine parameter
        engine_orig = create_engine('sqlite://')
        engine = construct_engine(engine_orig)
        self.assertEqual(engine, engine_orig)

        # test precedance
        engine = construct_engine(url,
                                  engine_dict={'encoding': False},
                                  engine_arg_encoding=True)
        self.assertTrue(engine.dialect.encoding)

        # deprecated echo=True parameter
        try:
            # py 2.4 compatability :-/
            cw = catch_warnings(record=True)
            w = cw.__enter__()

            warnings.simplefilter("always")
            engine = construct_engine(url, echo='True')
            self.assertTrue(engine.echo)

            self.assertEqual(len(w), 1)
            self.assertTrue(
                issubclass(w[-1].category, MigrateDeprecationWarning))
            self.assertEqual(
                'echo=True parameter is deprecated, pass '
                'engine_arg_echo=True or engine_dict={"echo": True}',
                str(w[-1].message))

        finally:
            cw.__exit__()

        # unsupported argument
        self.assertRaises(ValueError, construct_engine, 1)
Exemplo n.º 4
0
    def test_construct_engine(self):
        """Construct engine the smart way"""
        url = 'sqlite://'

        engine = construct_engine(url)
        self.assertTrue(engine.name == 'sqlite')

        # keyword arg
        engine = construct_engine(url, engine_arg_encoding='utf-8')
        self.assertEqual(engine.dialect.encoding, 'utf-8')

        # dict
        engine = construct_engine(url, engine_dict={'encoding': 'utf-8'})
        self.assertEqual(engine.dialect.encoding, 'utf-8')

        # engine parameter
        engine_orig = create_engine('sqlite://')
        engine = construct_engine(engine_orig)
        self.assertEqual(engine, engine_orig)

        # test precedance
        engine = construct_engine(url, engine_dict={'encoding': 'iso-8859-1'},
            engine_arg_encoding='utf-8')
        self.assertEqual(engine.dialect.encoding, 'utf-8')

        # deprecated echo=True parameter
        try:
            # py 2.4 compatability :-/
            cw = catch_warnings(record=True)
            w = cw.__enter__()

            warnings.simplefilter("always")
            engine = construct_engine(url, echo='True')
            self.assertTrue(engine.echo)

            self.assertEqual(len(w),1)
            self.assertTrue(issubclass(w[-1].category,
                                       MigrateDeprecationWarning))
            self.assertEqual(
                'echo=True parameter is deprecated, pass '
                'engine_arg_echo=True or engine_dict={"echo": True}',
                str(w[-1].message))

        finally:
            cw.__exit__()

        # unsupported argument
        self.assertRaises(ValueError, construct_engine, 1)
    def test_alter_deprecated(self):
        try:
            # py 2.4 compatability :-/
            cw = catch_warnings(record=True)
            w = cw.__enter__()

            warnings.simplefilter("always")
            self.table.c.data.alter(Column('data', String(100)))

            self.assertEqual(len(w), 1)
            self.assertTrue(
                issubclass(w[-1].category, MigrateDeprecationWarning))
            self.assertEqual(
                'Passing a Column object to alter_column is deprecated. '
                'Just pass in keyword parameters instead.', str(w[-1].message))
        finally:
            cw.__exit__()
Exemplo n.º 6
0
    def test_alter_deprecated(self):
        try:
            # py 2.4 compatability :-/
            cw = catch_warnings(record=True)
            w = cw.__enter__()

            warnings.simplefilter("always")
            self.table.c.data.alter(Column("data", String(100)))

            self.assertEqual(len(w), 1)
            self.assertTrue(issubclass(w[-1].category, MigrateDeprecationWarning))
            self.assertEqual(
                "Passing a Column object to alter_column is deprecated. " "Just pass in keyword parameters instead.",
                str(w[-1].message),
            )
        finally:
            cw.__exit__()