diff --git a/azure-pipelines.yml b/azure-pipelines.yml new file mode 100644 index 00000000..827afa29 --- /dev/null +++ b/azure-pipelines.yml @@ -0,0 +1,32 @@ +# Python package +# Create and test a Python package on multiple Python versions. +# Add steps that analyze code, save the dist with the build record, publish to a PyPI-compatible index, and more: +# https://docs.microsoft.com/azure/devops/pipelines/languages/python + +trigger: +- master + +pool: + vmImage: ubuntu-latest +strategy: + matrix: + Python35: + python.version: '3.5' + Python37: + python.version: '3.10' + +steps: +- task: UsePythonVersion@0 + inputs: + versionSpec: '$(python.version)' + displayName: 'Use Python $(python.version)' + +- script: | + python -m pip install --upgrade pip + pip install -r requirements.txt + displayName: 'Install dependencies' + +- script: | + pip install pytest pytest-azurepipelines + pytest + displayName: 'pytest' diff --git a/pyhive/common.py b/pyhive/common.py index 298633a1..99fe55c8 100644 --- a/pyhive/common.py +++ b/pyhive/common.py @@ -234,7 +234,14 @@ def escape_sequence(self, item): return '(' + ','.join(l) + ')' def escape_datetime(self, item, format, cutoff=0): - dt_str = item.strftime(format) + if format.startswith('%Y'): + # patch for #404 + dt_str = '{:0>4}{}'.format( + item.strftime('%Y'), + item.strftime(format.lstrip('%Y')) + ) + else: + dt_str = item.strftime(format) formatted = dt_str[:-cutoff] if cutoff and format.endswith(".%f") else dt_str return "'{}'".format(formatted) diff --git a/pyhive/tests/test_common.py b/pyhive/tests/test_common.py index 715c7168..8642610f 100644 --- a/pyhive/tests/test_common.py +++ b/pyhive/tests/test_common.py @@ -38,3 +38,7 @@ def test_escape_args(self): ("'2020-04-17'",)) self.assertEqual(escaper.escape_args((datetime.datetime(2020, 4, 17, 12, 0, 0, 123456),)), ("'2020-04-17 12:00:00.123456'",)) + self.assertEqual(escaper.escape_args((datetime.date(2020, 4, 17),)), + ("'2020-04-17'",)) + self.assertEqual(escaper.escape_args((datetime.datetime(20, 4, 17, 12, 0, 0, 123456),)), + ("'0020-04-17 12:00:00.123456'",))