# encoding: utf-8

"""
.. codeauthor:: Tsuyoshi Hombashi <tsuyoshi.hombashi@gmail.com>
"""

from __future__ import unicode_literals

import pytest
from simplesqlite.query import And, Or, Where
from simplesqlite.sqlquery import SqlQuery


nan = float("nan")
inf = float("inf")


class Test_SqlQuery_make_insert(object):
    @pytest.mark.parametrize(
        ["table", "insert_tuple", "expected"],
        [
            ["A", ["B"], "INSERT INTO A VALUES (?)"],
            ["A", ["B", "C"], "INSERT INTO A VALUES (?,?)"],
            ["A", ["AAAA", 2, 0.1], "INSERT INTO A VALUES (?,?,?)"],
        ],
    )
    def test_normal(self, table, insert_tuple, expected):
        assert SqlQuery.make_insert(table, insert_tuple) == expected

    @pytest.mark.parametrize(
        ["table", "insert_tuple", "is_isert_many", "expected"],
        [
            ["", [], False, ValueError],
            ["", None, True, ValueError],
            ["", ["B"], False, ValueError],
            ["A", [], True, ValueError],
            ["A", None, False, ValueError],
            [None, None, True, ValueError],
            [None, ["B"], False, ValueError],
            [None, [], True, ValueError],
        ],
    )
    def test_exception(self, table, insert_tuple, is_isert_many, expected):
        with pytest.raises(expected):
            SqlQuery.make_insert(table, insert_tuple)


class Test_SqlQuery_make_update(object):
    @pytest.mark.parametrize(
        ["table", "set_query", "where", "expected"],
        [
            ["A", "B=1", None, "UPDATE A SET B=1"],
            ["A", "B=1", Where("C", 1, ">").to_query(), "UPDATE A SET B=1 WHERE C > 1"],
            ["A", "B=1", Where("C", 1, ">"), "UPDATE A SET B=1 WHERE C > 1"],
            [
                "A",
                "B=1",
                And([Where("C", 1, ">"), Where("D", 10)]),
                "UPDATE A SET B=1 WHERE C > 1 AND D = 10",
            ],
            [
                "A",
                "B=1",
                Or([Where("C", 1, ">"), Where("D", 10)]),
                "UPDATE A SET B=1 WHERE C > 1 OR D = 10",
            ],
        ],
    )
    def test_normal(self, table, set_query, where, expected):
        assert SqlQuery.make_update(table, set_query, where) == expected

    @pytest.mark.parametrize(
        ["table", "set_query", "where", "expected"],
        [
            [None, "B=1", None, ValueError],
            ["", "B=1", None, ValueError],
            ["A", None, None, ValueError],
            ["A", "", None, ValueError],
        ],
    )
    def test_exception(self, table, set_query, where, expected):
        with pytest.raises(expected):
            SqlQuery.make_update(table, set_query, where)


class Test_SqlQuery_make_where_in(object):
    @pytest.mark.parametrize(
        ["key", "value", "expected"], [["key", ["attr_a", "attr_b"], "key IN ('attr_a', 'attr_b')"]]
    )
    def test_normal(self, key, value, expected):
        assert SqlQuery.make_where_in(key, value) == expected

    @pytest.mark.parametrize(
        ["key", "value", "expected"],
        [
            ["key", None, TypeError],
            ["key", 1, TypeError],
            [None, ["attr_a", "attr_b"], TypeError],
            [None, None, TypeError],
        ],
    )
    def test_exception(self, key, value, expected):
        with pytest.raises(expected):
            SqlQuery.make_where_in(key, value)


class Test_SqlQuery_make_where_not_in(object):
    @pytest.mark.parametrize(
        ["key", "value", "expected"],
        [["key", ["attr_a", "attr_b"], "key NOT IN ('attr_a', 'attr_b')"]],
    )
    def test_normal(self, key, value, expected):
        assert SqlQuery.make_where_not_in(key, value) == expected

    @pytest.mark.parametrize(
        ["key", "value", "expected"],
        [
            ["key", None, TypeError],
            ["key", 1, TypeError],
            [None, ["attr_a", "attr_b"], TypeError],
            [None, None, TypeError],
        ],
    )
    def test_exception(self, key, value, expected):
        with pytest.raises(expected):
            SqlQuery.make_where_not_in(key, value)

@@ -275,1100 +275,8 @@
 )%0A%0A%0A
-class Test_SqlQuery_make_insert(object):%0A    @pytest.mark.parametrize(%0A        %5B%22table%22, %22insert_tuple%22, %22expected%22%5D,%0A        %5B%0A            %5B%22A%22, %5B%22B%22%5D, %22INSERT INTO A VALUES (?)%22%5D,%0A            %5B%22A%22, %5B%22B%22, %22C%22%5D, %22INSERT INTO A VALUES (?,?)%22%5D,%0A            %5B%22A%22, %5B%22AAAA%22, 2, 0.1%5D, %22INSERT INTO A VALUES (?,?,?)%22%5D,%0A        %5D,%0A    )%0A    def test_normal(self, table, insert_tuple, expected):%0A        assert SqlQuery.make_insert(table, insert_tuple) == expected%0A%0A    @pytest.mark.parametrize(%0A        %5B%22table%22, %22insert_tuple%22, %22is_isert_many%22, %22expected%22%5D,%0A        %5B%0A            %5B%22%22, %5B%5D, False, ValueError%5D,%0A            %5B%22%22, None, True, ValueError%5D,%0A            %5B%22%22, %5B%22B%22%5D, False, ValueError%5D,%0A            %5B%22A%22, %5B%5D, True, ValueError%5D,%0A            %5B%22A%22, None, False, ValueError%5D,%0A            %5BNone, None, True, ValueError%5D,%0A            %5BNone, %5B%22B%22%5D, False, ValueError%5D,%0A            %5BNone, %5B%5D, True, ValueError%5D,%0A        %5D,%0A    )%0A    def test_exception(self, table, insert_tuple, is_isert_many, expected):%0A        with pytest.raises(expected):%0A            SqlQuery.make_insert(table, insert_tuple)%0A%0A%0A
 clas

Remove test cases that no longer needed