Python sqlalchemy.exc.ArgumentError() Examples

The following are 30 code examples of sqlalchemy.exc.ArgumentError(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module sqlalchemy.exc , or try the search function .
Example #1
Source File: test_types.py    From sqlalchemy with MIT License 8 votes vote down vote up
def test_detect_coercion_of_builtins(self):
        @inspection._self_inspects
        class SomeSQLAThing(object):
            def __repr__(self):
                return "some_sqla_thing()"

        class SomeOtherThing(object):
            pass

        assert_raises_message(
            exc.ArgumentError,
            r"SQL expression element or literal value expected, got "
            r"some_sqla_thing\(\).",
            lambda: column("a", String) == SomeSQLAThing(),
        )

        is_(bindparam("x", SomeOtherThing()).type, types.NULLTYPE) 
Example #2
Source File: test_metadata.py    From sqlalchemy with MIT License 6 votes vote down vote up
def test_auto_append_uq_on_col_attach_three(self):
        m = MetaData()

        a = Column("a", Integer)
        b = Column("b", Integer)
        c = Column("c", Integer)
        uq = UniqueConstraint(a, b, c)

        t = Table("tbl", m, a)
        assert uq not in t.constraints

        t.append_column(b)
        assert uq not in t.constraints

        t2 = Table("t2", m)

        # two different tables, so UniqueConstraint raises
        assert_raises_message(
            exc.ArgumentError,
            r"Column\(s\) 't2\.c' are not part of table 'tbl'\.",
            t2.append_column,
            c,
        ) 
Example #3
Source File: test_utils.py    From sqlalchemy with MIT License 6 votes vote down vote up
def test_separate_key_cols(self):
        c1, c2 = sql.column("col1"), sql.column("col2")
        assert_raises_message(
            exc.ArgumentError,
            "DedupeColumnCollection requires columns be under "
            "the same key as their .key",
            self._column_collection,
            [("kcol1", c1), ("kcol2", c2)],
        )

        cc = self._column_collection()
        assert_raises_message(
            exc.ArgumentError,
            "DedupeColumnCollection requires columns be under "
            "the same key as their .key",
            cc.add,
            c1,
            "kcol1",
        ) 
Example #4
Source File: test_utils.py    From sqlalchemy with MIT License 6 votes vote down vote up
def test_in(self):
        col1 = sql.column("col1")
        cc = self._column_collection(
            columns=[
                ("col1", col1),
                ("col2", sql.column("col2")),
                ("col3", sql.column("col3")),
            ]
        )
        assert "col1" in cc
        assert "col2" in cc

        assert_raises_message(
            exc.ArgumentError,
            "__contains__ requires a string argument",
            lambda: col1 in cc,
        ) 
Example #5
Source File: resource.py    From local-data-api with MIT License 6 votes vote down vote up
def create_query(cls, sql: str, params: Dict[str, Any]) -> str:
        text_sql: TextClause = text(sql)
        kwargs = {'dialect': cls.DIALECT, 'compile_kwargs': {"literal_binds": True}}
        try:
            return str(
                text_sql.bindparams(
                    **{k: null() if v is None else v for k, v in params.items()}
                ).compile(**kwargs)
            )
        except CompileError as e:
            invalid_param_match = re.match(INVALID_PARAMETER_MESSAGE, e.args[0])
            if invalid_param_match:  # pragma: no cover
                raise BadRequestException(
                    message=f'Cannot find parameter: {invalid_param_match.group(1)}'
                )
            raise  # pragma: no cover
        except ArgumentError as e:
            undefined_param_match = re.match(UNDEFINED_PARAMETER_MESSAGE, e.args[0])
            if undefined_param_match:  # pragma: no cover
                undefined_param: str = undefined_param_match.group(1)
                return cls.create_query(
                    sql, {k: v for k, v in params.items() if k != undefined_param}
                )
            raise  # pragma: no cover 
Example #6
Source File: test_compiler.py    From sqlalchemy with MIT License 6 votes vote down vote up
def test_over_invalid_framespecs(self):
        assert_raises_message(
            exc.ArgumentError,
            "Integer or None expected for range value",
            func.row_number().over,
            range_=("foo", 8),
        )

        assert_raises_message(
            exc.ArgumentError,
            "Integer or None expected for range value",
            func.row_number().over,
            range_=(-5, "foo"),
        )

        assert_raises_message(
            exc.ArgumentError,
            "'range_' and 'rows' are mutually exclusive",
            func.row_number().over,
            range_=(-5, 8),
            rows=(-2, 5),
        ) 
Example #7
Source File: test_computed.py    From sqlalchemy with MIT License 6 votes vote down vote up
def test_server_default_onupdate(self):
        text = (
            "A generated column cannot specify a server_default or a "
            "server_onupdate argument"
        )

        def fn(**kwargs):
            m = MetaData()
            Table(
                "t",
                m,
                Column("x", Integer),
                Column("y", Integer, Computed("x + 2"), **kwargs),
            )

        assert_raises_message(ArgumentError, text, fn, server_default="42")
        assert_raises_message(ArgumentError, text, fn, server_onupdate="42") 
Example #8
Source File: pysqlite.py    From stdm with GNU General Public License v2.0 6 votes vote down vote up
def create_connect_args(self, url):
        if url.username or url.password or url.host or url.port:
            raise exc.ArgumentError(
                "Invalid SQLite URL: %s\n"
                "Valid SQLite URL forms are:\n"
                " sqlite:///:memory: (or, sqlite://)\n"
                " sqlite:///relative/path/to/file.db\n"
                " sqlite:////absolute/path/to/file.db" % (url,))
        filename = url.database or ':memory:'
        if filename != ':memory:':
            filename = os.path.abspath(filename)

        opts = url.query.copy()
        util.coerce_kw_type(opts, 'timeout', float)
        util.coerce_kw_type(opts, 'isolation_level', str)
        util.coerce_kw_type(opts, 'detect_types', int)
        util.coerce_kw_type(opts, 'check_same_thread', bool)
        util.coerce_kw_type(opts, 'cached_statements', int)

        return ([filename], opts) 
Example #9
Source File: pysqlite.py    From jbox with MIT License 6 votes vote down vote up
def create_connect_args(self, url):
        if url.username or url.password or url.host or url.port:
            raise exc.ArgumentError(
                "Invalid SQLite URL: %s\n"
                "Valid SQLite URL forms are:\n"
                " sqlite:///:memory: (or, sqlite://)\n"
                " sqlite:///relative/path/to/file.db\n"
                " sqlite:////absolute/path/to/file.db" % (url,))
        filename = url.database or ':memory:'
        if filename != ':memory:':
            filename = os.path.abspath(filename)

        opts = url.query.copy()
        util.coerce_kw_type(opts, 'timeout', float)
        util.coerce_kw_type(opts, 'isolation_level', str)
        util.coerce_kw_type(opts, 'detect_types', int)
        util.coerce_kw_type(opts, 'check_same_thread', bool)
        util.coerce_kw_type(opts, 'cached_statements', int)

        return ([filename], opts) 
Example #10
Source File: test_metadata.py    From sqlalchemy with MIT License 6 votes vote down vote up
def test_invalid_composite_fk_check_columns(self):
        m = MetaData()

        t2 = Table("t2", m, Column("x", Integer))
        t3 = Table("t3", m, Column("y", Integer))

        assert_raises_message(
            exc.ArgumentError,
            r"ForeignKeyConstraint on t1\(x, y\) refers to "
            "multiple remote tables: t2 and t3",
            Table,
            "t1",
            m,
            Column("x", Integer),
            Column("y", Integer),
            ForeignKeyConstraint(["x", "y"], [t2.c.x, t3.c.y]),
        ) 
Example #11
Source File: test_operators.py    From sqlalchemy with MIT License 6 votes vote down vote up
def test_in_no_accept_non_list_thing_with_getitem(self):
        # test [ticket:2726]
        class HasGetitem(String):
            class comparator_factory(String.Comparator):
                def __getitem__(self, value):
                    return value

        left = column("left")
        right = column("right", HasGetitem)
        assert_raises_message(
            exc.ArgumentError,
            r"IN expression list, SELECT construct, or bound parameter "
            r"object expected, got .*ColumnClause",
            left.in_,
            right,
        ) 
Example #12
Source File: test_metadata.py    From sqlalchemy with MIT License 6 votes vote down vote up
def test_raise_clauseelement_not_a_column(self):
        m = MetaData()
        t2 = Table("t2", m, Column("x", Integer))

        class SomeClass(object):
            def __clause_element__(self):
                return t2

        assert_raises_message(
            exc.ArgumentError,
            r"String column name or column expression for DDL constraint "
            r"expected, got .*SomeClass",
            Index,
            "foo",
            SomeClass(),
        ) 
Example #13
Source File: test_operators.py    From sqlalchemy with MIT License 6 votes vote down vote up
def test_illegal_ops(self, t_fixture):
        t = t_fixture

        assert_raises_message(
            exc.ArgumentError,
            "Only comparison operators may be used with ANY/ALL",
            lambda: 5 + all_(t.c.arrval),
        )

        # TODO:
        # this is invalid but doesn't raise an error,
        # as the left-hand side just does its thing.  Types
        # would need to reject their right-hand side.
        self.assert_compile(
            t.c.data + all_(t.c.arrval), "tab1.data + ALL (tab1.arrval)"
        ) 
Example #14
Source File: pysqlite.py    From pyRevit with GNU General Public License v3.0 6 votes vote down vote up
def create_connect_args(self, url):
        if url.username or url.password or url.host or url.port:
            raise exc.ArgumentError(
                "Invalid SQLite URL: %s\n"
                "Valid SQLite URL forms are:\n"
                " sqlite:///:memory: (or, sqlite://)\n"
                " sqlite:///relative/path/to/file.db\n"
                " sqlite:////absolute/path/to/file.db" % (url,))
        filename = url.database or ':memory:'
        if filename != ':memory:':
            filename = os.path.abspath(filename)

        opts = url.query.copy()
        util.coerce_kw_type(opts, 'timeout', float)
        util.coerce_kw_type(opts, 'isolation_level', str)
        util.coerce_kw_type(opts, 'detect_types', int)
        util.coerce_kw_type(opts, 'check_same_thread', bool)
        util.coerce_kw_type(opts, 'cached_statements', int)

        return ([filename], opts) 
Example #15
Source File: pysqlite.py    From planespotter with MIT License 6 votes vote down vote up
def create_connect_args(self, url):
        if url.username or url.password or url.host or url.port:
            raise exc.ArgumentError(
                "Invalid SQLite URL: %s\n"
                "Valid SQLite URL forms are:\n"
                " sqlite:///:memory: (or, sqlite://)\n"
                " sqlite:///relative/path/to/file.db\n"
                " sqlite:////absolute/path/to/file.db" % (url,))
        filename = url.database or ':memory:'
        if filename != ':memory:':
            filename = os.path.abspath(filename)

        opts = url.query.copy()
        util.coerce_kw_type(opts, 'timeout', float)
        util.coerce_kw_type(opts, 'isolation_level', str)
        util.coerce_kw_type(opts, 'detect_types', int)
        util.coerce_kw_type(opts, 'check_same_thread', bool)
        util.coerce_kw_type(opts, 'cached_statements', int)

        return ([filename], opts) 
Example #16
Source File: test_on_duplicate.py    From sqlalchemy with MIT License 6 votes vote down vote up
def test_bad_args(self):
        assert_raises(
            ValueError,
            insert(self.tables.foos, values={}).on_duplicate_key_update,
        )
        assert_raises(
            exc.ArgumentError,
            insert(self.tables.foos, values={}).on_duplicate_key_update,
            {"id": 1, "bar": "b"},
            id=1,
            bar="b",
        )
        assert_raises(
            exc.ArgumentError,
            insert(self.tables.foos, values={}).on_duplicate_key_update,
            {"id": 1, "bar": "b"},
            {"id": 2, "bar": "baz"},
        ) 
Example #17
Source File: pysqlite.py    From Fluid-Designer with GNU General Public License v3.0 6 votes vote down vote up
def create_connect_args(self, url):
        if url.username or url.password or url.host or url.port:
            raise exc.ArgumentError(
                "Invalid SQLite URL: %s\n"
                "Valid SQLite URL forms are:\n"
                " sqlite:///:memory: (or, sqlite://)\n"
                " sqlite:///relative/path/to/file.db\n"
                " sqlite:////absolute/path/to/file.db" % (url,))
        filename = url.database or ':memory:'
        if filename != ':memory:':
            filename = os.path.abspath(filename)

        opts = url.query.copy()
        util.coerce_kw_type(opts, 'timeout', float)
        util.coerce_kw_type(opts, 'isolation_level', str)
        util.coerce_kw_type(opts, 'detect_types', int)
        util.coerce_kw_type(opts, 'check_same_thread', bool)
        util.coerce_kw_type(opts, 'cached_statements', int)

        return ([filename], opts) 
Example #18
Source File: test_metadata.py    From sqlalchemy with MIT License 5 votes vote down vote up
def test_invalid_composite_fk_check_strings(self):
        m = MetaData()

        assert_raises_message(
            exc.ArgumentError,
            r"ForeignKeyConstraint on t1\(x, y\) refers to "
            "multiple remote tables: t2 and t3",
            Table,
            "t1",
            m,
            Column("x", Integer),
            Column("y", Integer),
            ForeignKeyConstraint(["x", "y"], ["t2.x", "t3.y"]),
        ) 
Example #19
Source File: test_roles.py    From sqlalchemy with MIT License 5 votes vote down vote up
def test_select_statement_no_text_coercion(self):
        assert_raises_message(
            exc.ArgumentError,
            r"Textual SQL expression 'select \* from table' should be "
            r"explicitly declared",
            expect,
            roles.SelectStatementRole,
            "select * from table",
        ) 
Example #20
Source File: test_roles.py    From sqlalchemy with MIT License 5 votes vote down vote up
def test_statement_no_text_coercion(self):
        assert_raises_message(
            exc.ArgumentError,
            r"Textual SQL expression 'select \* from table' should be "
            r"explicitly declared",
            expect,
            roles.StatementRole,
            "select * from table",
        ) 
Example #21
Source File: test_roles.py    From sqlalchemy with MIT License 5 votes vote down vote up
def test_from_clause_is_not_a_select(self):
        assert_raises_message(
            exc.ArgumentError,
            r"SELECT construct or equivalent text\(\) construct expected,",
            expect,
            roles.SelectStatementRole,
            FromGrouping(t),
        ) 
Example #22
Source File: test_metadata.py    From sqlalchemy with MIT License 5 votes vote down vote up
def test_invalid_objects(self):
        assert_raises_message(
            tsa.exc.ArgumentError,
            "'SchemaItem' object, such as a 'Column' or a "
            "'Constraint' expected, got <.*ColumnClause at .*; q>",
            Table,
            "asdf",
            MetaData(),
            tsa.column("q", Integer),
        )

        assert_raises_message(
            tsa.exc.ArgumentError,
            r"'SchemaItem' object, such as a 'Column' or a "
            r"'Constraint' expected, got String\(\)",
            Table,
            "asdf",
            MetaData(),
            String(),
        )

        assert_raises_message(
            tsa.exc.ArgumentError,
            "'SchemaItem' object, such as a 'Column' or a "
            "'Constraint' expected, got 12",
            Table,
            "asdf",
            MetaData(),
            12,
        ) 
Example #23
Source File: test_roles.py    From sqlalchemy with MIT License 5 votes vote down vote up
def _test_role_neg_comparisons(self, role):
        impl = coercions._impl_lookup[role]
        role_name = impl.name

        assert_raises_message(
            exc.ArgumentError,
            r"%s expected, got .*NotAThing1" % role_name,
            expect,
            role,
            not_a_thing1,
        )

        assert_raises_message(
            exc.ArgumentError,
            r"%s expected, got .*NotAThing2" % role_name,
            expect,
            role,
            not_a_thing2,
        )

        assert_raises_message(
            exc.ArgumentError,
            r"%s expected, got .*NotAThing3" % role_name,
            expect,
            role,
            not_a_thing3,
        )

        assert_raises_message(
            exc.ArgumentError,
            r"%s expected for argument 'foo'; got .*NotAThing3" % role_name,
            expect,
            role,
            not_a_thing3,
            argname="foo",
        ) 
Example #24
Source File: test_compiler.py    From sqlalchemy with MIT License 5 votes vote down vote up
def test_schema_lowercase_invalid(self):
        assert_raises_message(
            exc.ArgumentError,
            r"Unsupported argument\(s\): \['not_a_schema'\]",
            table,
            "foo",
            not_a_schema="bar",
        ) 
Example #25
Source File: test_compiler.py    From sqlalchemy with MIT License 5 votes vote down vote up
def test_invalid_col_argument(self):
        assert_raises(exc.ArgumentError, select, table1)
        assert_raises(exc.ArgumentError, select, table1.c.myid) 
Example #26
Source File: test_compiler.py    From sqlalchemy with MIT License 5 votes vote down vote up
def test_prefix_constructor(self):
        class Pref(HasPrefixes):
            def _generate(self):
                return self

        assert_raises(
            exc.ArgumentError,
            Pref().prefix_with,
            "some prefix",
            not_a_dialect=True,
        ) 
Example #27
Source File: test_case_statement.py    From sqlalchemy with MIT License 5 votes vote down vote up
def test_literal_interpretation_ambiguous_tuple(self):
        assert_raises_message(
            exc.ArgumentError,
            r"Column expression expected, got \('x', 'y'\)",
            case,
            [(("x", "y"), "z")],
        ) 
Example #28
Source File: test_case_statement.py    From sqlalchemy with MIT License 5 votes vote down vote up
def test_literal_interpretation_ambiguous(self):
        assert_raises_message(
            exc.ArgumentError,
            r"Column expression expected, got 'x'",
            case,
            [("x", "y")],
        ) 
Example #29
Source File: test_text.py    From sqlalchemy with MIT License 5 votes vote down vote up
def test_missing_bind_posn(self):
        assert_raises_message(
            exc.ArgumentError,
            r"This text\(\) construct doesn't define "
            r"a bound parameter named 'bar'",
            text(":foo").bindparams,
            bindparam("foo", value=5),
            bindparam("bar", value=7),
        ) 
Example #30
Source File: test_text.py    From sqlalchemy with MIT License 5 votes vote down vote up
def test_missing_bind_kw(self):
        assert_raises_message(
            exc.ArgumentError,
            r"This text\(\) construct doesn't define "
            r"a bound parameter named 'bar'",
            text(":foo").bindparams,
            foo=5,
            bar=7,
        )