Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_day_of_week(self):
f = ClassicFormatter()
d = Pendulum(2016, 8, 28)
self.assertEqual('Sun', f.format(d, '%a'))
self.assertEqual('Sunday', f.format(d, '%A'))
self.assertEqual('dim', f.format(d, '%a', locale='fr'))
self.assertEqual('dimanche', f.format(d, '%A', locale='fr'))
def test_start_of_year_from_first_day(self):
d = Pendulum(2000, 1, 1, 1, 1, 1)
new = d.start_of('year')
self.assertPendulum(new, 2000, 1, 1, 0, 0, 0)
def test_start_of_second(self):
d = Pendulum.now()
new = d.start_of('second')
self.assertIsInstanceOfPendulum(new)
self.assertPendulum(new, d.year, d.month, d.day, d.hour, d.minute, d.second, 0)
def test_start_of_with_transition(self):
d = Pendulum(2013, 10, 27, 23, 59, 59, tzinfo='Europe/Paris')
self.assertEqual(3600, d.offset)
self.assertEqual(7200, d.start_of('month').offset)
self.assertEqual(7200, d.start_of('day').offset)
self.assertEqual(3600, d.start_of('year').offset)
def test_end_of_week(self):
d = Pendulum(1980, 8, 7, 12, 11, 9).end_of('week')
self.assertPendulum(d, 1980, 8, 10, 23, 59, 59)
def __init__(self):
self.pendulum = Pendulum(1)
self.pendulum.DT = DT
self.pendulum.NDT = 5
session, source_table, event_time_col="event_time"
)
unprocessed_dates = [
date
for date in dates_present
if ETLRecord.can_process(
cdr_type=cdr_type, cdr_date=date, session=session
)
]
logger.info(f"Dates found: {dates_present}")
logger.info(f"Unprocessed dates: {unprocessed_dates}")
for cdr_date in unprocessed_dates:
uuid = uuid1()
cdr_date_str = cdr_date.strftime("%Y%m%d")
execution_date = pendulum.Pendulum(
cdr_date.year, cdr_date.month, cdr_date.day
)
config = {
"cdr_type": cdr_type,
"cdr_date": cdr_date,
"source_table": source_table,
}
trigger_dag(
f"etl_{cdr_type}",
execution_date=execution_date,
run_id=f"{cdr_type.upper()}_{cdr_date_str}-{str(uuid)}",
conf=config,
replace_microseconds=False,
)
else:
raise ValueError(f"Invalid source type: '{source_type}'")
"""
if not isinstance(start, datetime.date):
raise TypeError('start must be a datetime.date. Got {!r}'.format(start))
if not isinstance(end, datetime.date):
raise TypeError('end must be a datetime.date. Got {!r}'.format(end))
if start >= end:
raise ValueError('start must be before end. {!r} > {!r}'.format(start, end))
if limit == 0:
return # No need to do anything
# Cast to datetimes for compat reasons
start = pendulum.Pendulum.instance(datetime.datetime.combine(start, datetime.time(0, 0, 0, 0, timezone.utc)))
end = pendulum.Pendulum.instance(datetime.datetime.combine(end, datetime.time(0, 0, 0, 0, timezone.utc)))
if hasattr(self, 'shift_range'):
warnings.warn(
'{!r} implements a deprecated interface. '
'Handle date transforms in _do_fetch. '
'shift_range will no longer be called in SHARE 2.9.0'.format(self),
DeprecationWarning
)
start, end = self.shift_range(start, end)
data_gen = self._do_fetch(start, end, **self._get_kwargs(**kwargs))
if not isinstance(data_gen, types.GeneratorType) and len(data_gen) != 0:
raise TypeError('{!r}._do_fetch must return a GeneratorType for optimal performance and memory usage'.format(self))
def _validate_dates(self, start_date, end_date):
assert not (bool(start_date) ^ bool(end_date)), 'Must specify both a start and end date or neither'
assert isinstance(start_date, (datetime.timedelta, datetime.datetime, pendulum.Pendulum)) and isinstance(end_date, (datetime.timedelta, datetime.datetime, pendulum.Pendulum)), 'start_date and end_date must be either datetimes or timedeltas'
assert not (isinstance(start_date, datetime.timedelta) and isinstance(end_date, datetime.timedelta)), 'Only one of start_date and end_date may be a timedelta'
if isinstance(start_date, datetime.datetime):
start_date = pendulum.instance(start_date)
if isinstance(end_date, datetime.datetime):
end_date = pendulum.instance(end_date)
if isinstance(start_date, datetime.timedelta):
start_date = pendulum.instance(end_date + start_date)
if isinstance(end_date, datetime.timedelta):
end_date = pendulum.instance(start_date + end_date)
og_start, og_end = start_date, end_date
start_date, end_date = self.shift_range(start_date, end_date)
"""
if not isinstance(start, datetime.date):
raise TypeError('start must be a datetime.date. Got {!r}'.format(start))
if not isinstance(end, datetime.date):
raise TypeError('end must be a datetime.date. Got {!r}'.format(end))
if start >= end:
raise ValueError('start must be before end. {!r} > {!r}'.format(start, end))
if limit == 0:
return # No need to do anything
# Cast to datetimes for compat reasons
start = pendulum.Pendulum.instance(datetime.datetime.combine(start, datetime.time(0, 0, 0, 0, timezone.utc)))
end = pendulum.Pendulum.instance(datetime.datetime.combine(end, datetime.time(0, 0, 0, 0, timezone.utc)))
if hasattr(self, 'shift_range'):
warnings.warn(
'{!r} implements a deprecated interface. '
'Handle date transforms in _do_fetch. '
'shift_range will no longer be called in SHARE 2.9.0'.format(self),
DeprecationWarning
)
start, end = self.shift_range(start, end)
data_gen = self._do_fetch(start, end, **self._get_kwargs(**kwargs))
if not isinstance(data_gen, types.GeneratorType) and len(data_gen) != 0:
raise TypeError('{!r}._do_fetch must return a GeneratorType for optimal performance and memory usage'.format(self))
for i, blob in enumerate(data_gen):