You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by be...@apache.org on 2023/08/07 21:02:49 UTC

[superset] branch update_sqlite_specs updated: Add more tests

This is an automated email from the ASF dual-hosted git repository.

beto pushed a commit to branch update_sqlite_specs
in repository https://gitbox.apache.org/repos/asf/superset.git


The following commit(s) were added to refs/heads/update_sqlite_specs by this push:
     new a8f56b306b Add more tests
a8f56b306b is described below

commit a8f56b306b06fb34368f8b2090a0f9a80145bfef
Author: Beto Dealmeida <ro...@dealmeida.net>
AuthorDate: Mon Aug 7 14:02:07 2023 -0700

    Add more tests
---
 tests/unit_tests/db_engine_specs/test_sqlite.py | 88 +++++++++++++++++--------
 1 file changed, 60 insertions(+), 28 deletions(-)

diff --git a/tests/unit_tests/db_engine_specs/test_sqlite.py b/tests/unit_tests/db_engine_specs/test_sqlite.py
index 11ce174c0f..a31992afcf 100644
--- a/tests/unit_tests/db_engine_specs/test_sqlite.py
+++ b/tests/unit_tests/db_engine_specs/test_sqlite.py
@@ -21,6 +21,7 @@ from typing import Optional
 import pytest
 from sqlalchemy.engine import create_engine
 
+from superset.constants import TimeGrain
 from tests.unit_tests.db_engine_specs.utils import assert_convert_dttm
 from tests.unit_tests.fixtures.common import dttm
 
@@ -47,13 +48,21 @@ def test_convert_dttm(
 @pytest.mark.parametrize(
     "dttm,grain,expected",
     [
-        ("2022-05-04T05:06:07.89Z", "PT1S", "2022-05-04 05:06:07"),
-        ("2022-05-04T05:06:07.89Z", "PT1M", "2022-05-04 05:06:00"),
-        ("2022-05-04T05:06:07.89Z", "PT1H", "2022-05-04 05:00:00"),
-        ("2022-05-04T05:06:07.89Z", "P1D", "2022-05-04 00:00:00"),
-        ("2022-05-04T05:06:07.89Z", "P1W", "2022-05-01 00:00:00"),
-        ("2022-05-04T05:06:07.89Z", "P1M", "2022-05-01 00:00:00"),
-        ("2022-05-04T05:06:07.89Z", "P1Y", "2022-01-01 00:00:00"),
+        ("2022-05-04T05:06:07.89Z", TimeGrain.SECOND, "2022-05-04 05:06:07"),
+        ("2022-05-04T05:06:07.89Z", TimeGrain.FIVE_SECONDS, "2022-05-04 05:06:05"),
+        ("2022-05-04T05:06:37.89Z", TimeGrain.THIRTY_SECONDS, "2022-05-04 05:06:30"),
+        ("2022-05-04T05:06:07.89Z", TimeGrain.MINUTE, "2022-05-04 05:06:00"),
+        ("2022-05-04T05:06:07.89Z", TimeGrain.FIVE_MINUTES, "2022-05-04 05:05:00"),
+        ("2022-05-04T05:36:07.89Z", TimeGrain.TEN_MINUTES, "2022-05-04 05:30:00"),
+        ("2022-05-04T05:46:07.89Z", TimeGrain.FIFTEEN_MINUTES, "2022-05-04 05:45:00"),
+        ("2022-05-04T05:36:07.89Z", TimeGrain.THIRTY_MINUTES, "2022-05-04 05:30:00"),
+        ("2022-05-04T05:36:07.89Z", TimeGrain.HALF_HOUR, "2022-05-04 05:30:00"),
+        ("2022-05-04T05:06:07.89Z", TimeGrain.HOUR, "2022-05-04 05:00:00"),
+        ("2022-05-04T07:06:07.89Z", TimeGrain.SIX_HOURS, "2022-05-04 06:00:00"),
+        ("2022-05-04T05:06:07.89Z", TimeGrain.DAY, "2022-05-04 00:00:00"),
+        ("2022-05-04T05:06:07.89Z", TimeGrain.WEEK, "2022-05-01 00:00:00"),
+        ("2022-05-04T05:06:07.89Z", TimeGrain.MONTH, "2022-05-01 00:00:00"),
+        ("2022-05-04T05:06:07.89Z", TimeGrain.YEAR, "2022-01-01 00:00:00"),
         #  ___________________________
         # |         May 2022          |
         # |---------------------------|
@@ -61,27 +70,50 @@ def test_convert_dttm(
         # |---+---+---+---+---+---+---|
         # | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
         #  ---------------------------
-        # week ending Saturday
-        ("2022-05-04T05:06:07.89Z", "P1W/1970-01-03T00:00:00Z", "2022-05-07 00:00:00"),
-        # week ending Sunday
-        ("2022-05-04T05:06:07.89Z", "P1W/1970-01-04T00:00:00Z", "2022-05-08 00:00:00"),
-        # week starting Sunday
-        ("2022-05-04T05:06:07.89Z", "1969-12-28T00:00:00Z/P1W", "2022-05-01 00:00:00"),
-        # week starting Monday
-        ("2022-05-04T05:06:07.89Z", "1969-12-29T00:00:00Z/P1W", "2022-05-02 00:00:00"),
-        # tests for quarter
-        ("2022-01-04T05:06:07.89Z", "P3M", "2022-01-01 00:00:00"),
-        ("2022-02-04T05:06:07.89Z", "P3M", "2022-01-01 00:00:00"),
-        ("2022-03-04T05:06:07.89Z", "P3M", "2022-01-01 00:00:00"),
-        ("2022-04-04T05:06:07.89Z", "P3M", "2022-04-01 00:00:00"),
-        ("2022-05-04T05:06:07.89Z", "P3M", "2022-04-01 00:00:00"),
-        ("2022-06-04T05:06:07.89Z", "P3M", "2022-04-01 00:00:00"),
-        ("2022-07-04T05:06:07.89Z", "P3M", "2022-07-01 00:00:00"),
-        ("2022-08-04T05:06:07.89Z", "P3M", "2022-07-01 00:00:00"),
-        ("2022-09-04T05:06:07.89Z", "P3M", "2022-07-01 00:00:00"),
-        ("2022-10-04T05:06:07.89Z", "P3M", "2022-10-01 00:00:00"),
-        ("2022-11-04T05:06:07.89Z", "P3M", "2022-10-01 00:00:00"),
-        ("2022-12-04T05:06:07.89Z", "P3M", "2022-10-01 00:00:00"),
+        (
+            "2022-05-04T05:06:07.89Z",
+            TimeGrain.WEEK_ENDING_SATURDAY,
+            "2022-05-07 00:00:00",
+        ),
+        (
+            "2022-05-04T05:06:07.89Z",
+            TimeGrain.WEEK_ENDING_SUNDAY,
+            "2022-05-08 00:00:00",
+        ),
+        (
+            "2022-05-04T05:06:07.89Z",
+            TimeGrain.WEEK_STARTING_SUNDAY,
+            "2022-05-01 00:00:00",
+        ),
+        (
+            "2022-05-04T05:06:07.89Z",
+            TimeGrain.WEEK_STARTING_MONDAY,
+            "2022-05-02 00:00:00",
+        ),
+        ("2022-01-04T05:06:07.89Z", TimeGrain.QUARTER_YEAR, "2022-01-01 00:00:00"),
+        ("2022-02-04T05:06:07.89Z", TimeGrain.QUARTER_YEAR, "2022-01-01 00:00:00"),
+        ("2022-03-04T05:06:07.89Z", TimeGrain.QUARTER_YEAR, "2022-01-01 00:00:00"),
+        ("2022-04-04T05:06:07.89Z", TimeGrain.QUARTER_YEAR, "2022-04-01 00:00:00"),
+        ("2022-05-04T05:06:07.89Z", TimeGrain.QUARTER_YEAR, "2022-04-01 00:00:00"),
+        ("2022-06-04T05:06:07.89Z", TimeGrain.QUARTER_YEAR, "2022-04-01 00:00:00"),
+        ("2022-07-04T05:06:07.89Z", TimeGrain.QUARTER_YEAR, "2022-07-01 00:00:00"),
+        ("2022-08-04T05:06:07.89Z", TimeGrain.QUARTER_YEAR, "2022-07-01 00:00:00"),
+        ("2022-09-04T05:06:07.89Z", TimeGrain.QUARTER_YEAR, "2022-07-01 00:00:00"),
+        ("2022-10-04T05:06:07.89Z", TimeGrain.QUARTER_YEAR, "2022-10-01 00:00:00"),
+        ("2022-11-04T05:06:07.89Z", TimeGrain.QUARTER_YEAR, "2022-10-01 00:00:00"),
+        ("2022-12-04T05:06:07.89Z", TimeGrain.QUARTER_YEAR, "2022-10-01 00:00:00"),
+        ("2022-01-04T05:06:07.89Z", TimeGrain.QUARTER, "2022-01-01 00:00:00"),
+        ("2022-02-04T05:06:07.89Z", TimeGrain.QUARTER, "2022-01-01 00:00:00"),
+        ("2022-03-04T05:06:07.89Z", TimeGrain.QUARTER, "2022-01-01 00:00:00"),
+        ("2022-04-04T05:06:07.89Z", TimeGrain.QUARTER, "2022-04-01 00:00:00"),
+        ("2022-05-04T05:06:07.89Z", TimeGrain.QUARTER, "2022-04-01 00:00:00"),
+        ("2022-06-04T05:06:07.89Z", TimeGrain.QUARTER, "2022-04-01 00:00:00"),
+        ("2022-07-04T05:06:07.89Z", TimeGrain.QUARTER, "2022-07-01 00:00:00"),
+        ("2022-08-04T05:06:07.89Z", TimeGrain.QUARTER, "2022-07-01 00:00:00"),
+        ("2022-09-04T05:06:07.89Z", TimeGrain.QUARTER, "2022-07-01 00:00:00"),
+        ("2022-10-04T05:06:07.89Z", TimeGrain.QUARTER, "2022-10-01 00:00:00"),
+        ("2022-11-04T05:06:07.89Z", TimeGrain.QUARTER, "2022-10-01 00:00:00"),
+        ("2022-12-04T05:06:07.89Z", TimeGrain.QUARTER, "2022-10-01 00:00:00"),
     ],
 )
 def test_time_grain_expressions(dttm: str, grain: str, expected: str) -> None: