(self)
| 2886 | ) |
| 2887 | |
| 2888 | def test_cast(self): |
| 2889 | tbl = table( |
| 2890 | "casttest", |
| 2891 | column("id", Integer), |
| 2892 | column("v1", Float), |
| 2893 | column("v2", Float), |
| 2894 | column("ts", TIMESTAMP), |
| 2895 | ) |
| 2896 | |
| 2897 | def check_results(dialect, expected_results, literal): |
| 2898 | eq_( |
| 2899 | len(expected_results), |
| 2900 | 5, |
| 2901 | "Incorrect number of expected results", |
| 2902 | ) |
| 2903 | eq_( |
| 2904 | str(cast(tbl.c.v1, Numeric).compile(dialect=dialect)), |
| 2905 | "CAST(casttest.v1 AS %s)" % expected_results[0], |
| 2906 | ) |
| 2907 | eq_( |
| 2908 | str(tbl.c.v1.cast(Numeric).compile(dialect=dialect)), |
| 2909 | "CAST(casttest.v1 AS %s)" % expected_results[0], |
| 2910 | ) |
| 2911 | eq_( |
| 2912 | str(cast(tbl.c.v1, Numeric(12, 9)).compile(dialect=dialect)), |
| 2913 | "CAST(casttest.v1 AS %s)" % expected_results[1], |
| 2914 | ) |
| 2915 | eq_( |
| 2916 | str(cast(tbl.c.ts, Date).compile(dialect=dialect)), |
| 2917 | "CAST(casttest.ts AS %s)" % expected_results[2], |
| 2918 | ) |
| 2919 | eq_( |
| 2920 | str(cast(1234, Text).compile(dialect=dialect)), |
| 2921 | "CAST(%s AS %s)" % (literal, expected_results[3]), |
| 2922 | ) |
| 2923 | eq_( |
| 2924 | str(cast("test", String(20)).compile(dialect=dialect)), |
| 2925 | "CAST(%s AS %s)" % (literal, expected_results[4]), |
| 2926 | ) |
| 2927 | |
| 2928 | # fixme: shoving all of this dialect-specific stuff in one test |
| 2929 | # is now officially completely ridiculous AND non-obviously omits |
| 2930 | # coverage on other dialects. |
| 2931 | sel = select(tbl, cast(tbl.c.v1, Numeric)).compile(dialect=dialect) |
| 2932 | |
| 2933 | # TODO: another unusual result from disambiguate only: |
| 2934 | # v1__1 vs v1_1 are due to the special meaning |
| 2935 | # WrapsColumnExpression gives to the "_anon_name_label" attribute, |
| 2936 | # where it tries to default to a label name that matches that of |
| 2937 | # the column within. |
| 2938 | |
| 2939 | if isinstance(dialect, type(mysql.dialect())): |
| 2940 | eq_( |
| 2941 | str(sel), |
| 2942 | "SELECT casttest.id, casttest.v1, casttest.v2, " |
| 2943 | "casttest.ts, " |
| 2944 | "CAST(casttest.v1 AS DECIMAL) AS v1__1 \n" |
| 2945 | "FROM casttest", |
nothing calls this directly
no test coverage detected