Skip to content

Commit

Permalink
Refactor 'import datetime' as 'import datetime as dt'
Browse files Browse the repository at this point in the history
  • Loading branch information
hugovk committed Oct 29, 2023
1 parent c0e52cf commit a63cb1a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 27 deletions.
16 changes: 8 additions & 8 deletions tests/test_tablib.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python
"""Tests for Tablib."""

import datetime
import datetime as dt
import doctest
import json
import pickle
Expand Down Expand Up @@ -304,8 +304,8 @@ def test_datetime_append(self):
"""Passes in a single datetime and a single date and exports."""

new_row = (
datetime.datetime.now(),
datetime.datetime.today(),
dt.datetime.now(),
dt.datetime.today(),
)

data.append(new_row)
Expand Down Expand Up @@ -1108,9 +1108,9 @@ def test_tsv_export(self):

class ODSTests(BaseTestCase):
def test_ods_export_import_set(self):
date = datetime.date(2019, 10, 4)
date_time = datetime.datetime(2019, 10, 4, 12, 30, 8)
time = datetime.time(14, 30)
date = dt.date(2019, 10, 4)
date_time = dt.datetime(2019, 10, 4, 12, 30, 8)
time = dt.time(14, 30)
data.append(('string', '004', 42, 21.55, Decimal('34.5'), date, time, date_time))
data.headers = (
'string', 'start0', 'integer', 'float', 'decimal', 'date', 'time', 'date/time'
Expand Down Expand Up @@ -1165,7 +1165,7 @@ def test_xls_date_import(self):
xls_source = Path(__file__).parent / 'files' / 'dates.xls'
with xls_source.open('rb') as fh:
dset = tablib.Dataset().load(fh, 'xls')
self.assertEqual(dset.dict[0]['birth_date'], datetime.datetime(2015, 4, 12, 0, 0))
self.assertEqual(dset.dict[0]['birth_date'], dt.datetime(2015, 4, 12, 0, 0))

def test_xlsx_import_set_skip_lines(self):
data.append(('garbage', 'line', ''))
Expand Down Expand Up @@ -1203,7 +1203,7 @@ def test_xlsx_format_detect(self):
self.assertEqual(detect_format(in_stream), 'xlsx')

def test_xlsx_import_set(self):
date_time = datetime.datetime(2019, 10, 4, 12, 30, 8)
date_time = dt.datetime(2019, 10, 4, 12, 30, 8)
data.append(('string', '004', 42, 21.55, date_time))
data.headers = ('string', 'start0', 'integer', 'float', 'date/time')
_xlsx = data.xlsx
Expand Down
38 changes: 19 additions & 19 deletions tests/test_tablib_dbfpy_packages_utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python
"""Tests for tablib.packages.dbfpy."""

import datetime
import datetime as dt
import unittest

from tablib.packages.dbfpy import utils
Expand Down Expand Up @@ -42,28 +42,28 @@ def test_getDate_none(self):
output = utils.getDate(value)

# Assert
self.assertIsInstance(output, datetime.date)
self.assertIsInstance(output, dt.date)

def test_getDate_datetime_date(self):
# Arrange
value = datetime.date(2019, 10, 19)
value = dt.date(2019, 10, 19)

# Act
output = utils.getDate(value)

# Assert
self.assertIsInstance(output, datetime.date)
self.assertIsInstance(output, dt.date)
self.assertEqual(output, value)

def test_getDate_datetime_datetime(self):
# Arrange
value = datetime.datetime(2019, 10, 19, 12, 00, 00)
value = dt.datetime(2019, 10, 19, 12, 00, 00)

# Act
output = utils.getDate(value)

# Assert
self.assertIsInstance(output, datetime.date)
self.assertIsInstance(output, dt.date)
self.assertEqual(output, value)

def test_getDate_datetime_timestamp(self):
Expand All @@ -74,8 +74,8 @@ def test_getDate_datetime_timestamp(self):
output = utils.getDate(value)

# Assert
self.assertIsInstance(output, datetime.date)
self.assertEqual(output, datetime.date(2019, 10, 19))
self.assertIsInstance(output, dt.date)
self.assertEqual(output, dt.date(2019, 10, 19))

def test_getDate_datetime_string_yyyy_mm_dd(self):
# Arrange
Expand All @@ -85,8 +85,8 @@ def test_getDate_datetime_string_yyyy_mm_dd(self):
output = utils.getDate(value)

# Assert
self.assertIsInstance(output, datetime.date)
self.assertEqual(output, datetime.date(2019, 10, 19))
self.assertIsInstance(output, dt.date)
self.assertEqual(output, dt.date(2019, 10, 19))

def test_getDate_datetime_string_yymmdd(self):
# Arrange
Expand All @@ -96,8 +96,8 @@ def test_getDate_datetime_string_yymmdd(self):
output = utils.getDate(value)

# Assert
self.assertIsInstance(output, datetime.date)
self.assertEqual(output, datetime.date(2019, 10, 19))
self.assertIsInstance(output, dt.date)
self.assertEqual(output, dt.date(2019, 10, 19))


class UtilsGetDateTimeTestCase(unittest.TestCase):
Expand All @@ -111,29 +111,29 @@ def test_getDateTime_none(self):
output = utils.getDateTime(value)

# Assert
self.assertIsInstance(output, datetime.datetime)
self.assertIsInstance(output, dt.datetime)

def test_getDateTime_datetime_datetime(self):
# Arrange
value = datetime.datetime(2019, 10, 19, 12, 00, 00)
value = dt.datetime(2019, 10, 19, 12, 00, 00)

# Act
output = utils.getDateTime(value)

# Assert
self.assertIsInstance(output, datetime.date)
self.assertIsInstance(output, dt.date)
self.assertEqual(output, value)

def test_getDateTime_datetime_date(self):
# Arrange
value = datetime.date(2019, 10, 19)
value = dt.date(2019, 10, 19)

# Act
output = utils.getDateTime(value)

# Assert
self.assertIsInstance(output, datetime.date)
self.assertEqual(output, datetime.datetime(2019, 10, 19, 00, 00))
self.assertIsInstance(output, dt.date)
self.assertEqual(output, dt.datetime(2019, 10, 19, 00, 00))

def test_getDateTime_datetime_timestamp(self):
# Arrange
Expand All @@ -143,7 +143,7 @@ def test_getDateTime_datetime_timestamp(self):
output = utils.getDateTime(value)

# Assert
self.assertIsInstance(output, datetime.datetime)
self.assertIsInstance(output, dt.datetime)

def test_getDateTime_datetime_string(self):
# Arrange
Expand Down

0 comments on commit a63cb1a

Please sign in to comment.