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_params_parse(self):
class TParseTask(TTask):
bool_param = parameter[bool]
int_param = parameter[int]
float_param = parameters.FloatParameter()
date_param = parameter[date]
timedelta_param = parameters.TimeDeltaParameter()
def run(self):
assert isinstance(self.float_param, float)
super(TParseTask, self).run()
target = TParseTask(
bool_param="yes",
int_param="666",
float_param="123.456",
date_param="2018-11-10",
timedelta_param="44d",
)
assert_run_task(target)
from typing import Dict
import pandas as pd
from databand import parameters
from dbnd import PipelineTask, output, parameter, task
from dbnd.testing.helpers_pytest import assert_run_task
from dbnd_test_scenarios.test_common.task.factories import TTask
class DummyTask(TTask):
float_param = parameters.FloatParameter()
expected_param = parameters.FloatParameter()
timedelta_param = parameters.TimeDeltaParameter()
expected_timedelta_param = parameters.TimeDeltaParameter()
def run(self):
assert isinstance(self.float_param, float)
assert isinstance(self.timedelta_param, timedelta)
assert self.float_param == self.expected_param
assert self.timedelta_param == self.expected_timedelta_param
super(DummyTask, self).run()
class DummyWrapper(PipelineTask):
defaults = {DummyTask.float_param: "0.1", DummyTask.timedelta_param: "4d"}
output = output
def band(self):
self.output = DummyTask().t_output
from datetime import date, timedelta
from typing import Dict
import pandas as pd
from databand import parameters
from dbnd import PipelineTask, output, parameter, task
from dbnd.testing.helpers_pytest import assert_run_task
from dbnd_test_scenarios.test_common.task.factories import TTask
class DummyTask(TTask):
float_param = parameters.FloatParameter()
expected_param = parameters.FloatParameter()
timedelta_param = parameters.TimeDeltaParameter()
expected_timedelta_param = parameters.TimeDeltaParameter()
def run(self):
assert isinstance(self.float_param, float)
assert isinstance(self.timedelta_param, timedelta)
assert self.float_param == self.expected_param
assert self.timedelta_param == self.expected_timedelta_param
super(DummyTask, self).run()
class DummyWrapper(PipelineTask):
defaults = {DummyTask.float_param: "0.1", DummyTask.timedelta_param: "4d"}
output = output
def band(self):
self.output = DummyTask().t_output
def testSerialize(self):
tdelta = datetime.timedelta(weeks=5, days=4, hours=3, minutes=2, seconds=1)
assert TimeDeltaParameter()._p.to_str(tdelta) == "5w 4d 3h 2m 1s"
tdelta = datetime.timedelta(seconds=0)
assert TimeDeltaParameter()._p.to_str(tdelta) == "0d"
dbnd.data,
databand.task,
tasks.DataSourceTask,
tasks.PipelineTask,
targets.Target,
targets.DataTarget,
dbnd._core.task_build.task_namespace.namespace,
parameters.Parameter,
parameters.DateHourParameter,
parameters.DateMinuteParameter,
parameters.DateSecondParameter,
parameters.DateParameter,
parameters.MonthParameter,
parameters.YearParameter,
parameters.DateIntervalParameter,
parameters.TimeDeltaParameter,
parameters.IntParameter,
parameters.FloatParameter,
parameters.BoolParameter,
]
assert len(expected) > 0
def test_no_warn_if_param_types_ok(self):
class DummyTask(TTask):
param = parameter[str]
bool_param = parameter[bool]
int_param = parameter[int]
float_param = parameter[float]
date_param = parameter[datetime]
datehour_param = DateHourParameter()
timedelta_param = TimeDeltaParameter()
insignificant_param = parameter(significant=False)[str]
DUMMY_TASK_OK_PARAMS = dict(
param="test",
bool_param=True,
int_param=666,
float_param=123.456,
date_param=datetime(2014, 9, 13).date(),
datehour_param=datetime(2014, 9, 13, 9, tzinfo=pytz.UTC),
timedelta_param=timedelta(44), # doesn't support seconds
insignificant_param="test",
)
with warnings.catch_warnings(record=True) as w:
DummyTask(**DUMMY_TASK_OK_PARAMS)
print([str(wm) for wm in w])