当前位置: 首页>>代码示例>>Python>>正文


Python pendulum.datetime方法代码示例

本文整理汇总了Python中pendulum.datetime方法的典型用法代码示例。如果您正苦于以下问题:Python pendulum.datetime方法的具体用法?Python pendulum.datetime怎么用?Python pendulum.datetime使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pendulum的用法示例。


在下文中一共展示了pendulum.datetime方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_arbitrary_schedule

# 需要导入模块: import pendulum [as 别名]
# 或者: from pendulum import datetime [as 别名]
def test_arbitrary_schedule():
    sample_date = pendulum.datetime(2019, 1, 31, 12, tz="America/Los_Angeles")
    schedule_path = "../sample_data/schedule/804_lametro-rail/2019-01-31.csv"

    assert (
        get_appropriate_timetable(
            sample_date, f"../sample_data/schedule/{line}_{agency}"
        )["path"]
        == schedule_path
    )

    assert (
        get_date_if_exists_otherwise_previous(
            sample_date, f"../sample_data/schedule/{line}_{agency}"
        )
        == sample_date
    ) 
开发者ID:metro-ontime,项目名称:performance_tracker,代码行数:19,代码来源:test_timing.py

示例2: test_from_human_with_timezone

# 需要导入模块: import pendulum [as 别名]
# 或者: from pendulum import datetime [as 别名]
def test_from_human_with_timezone(self):
        working_hours = WeeklyInterval('Mon', time(9, 00), 'Fri', time(17, 0))

        # During summer time
        now = pendulum.datetime(2019, 8, 30, tz='Europe/London')
        set_test_now(now)
        assert WeeklyInterval.from_human(
               "Mon 10:00 Europe/London - Fri 18:00 Europe/London"
        ) == working_hours

        # Outside summer time
        now = pendulum.datetime(2019, 12, 30, tz='Europe/London')
        set_test_now(now)
        assert WeeklyInterval.from_human(
            "Mon 09:00 Europe/London - Fri 17:00 Europe/London"
        ) == working_hours 
开发者ID:smarkets,项目名称:marge-bot,代码行数:18,代码来源:test_interval.py

示例3: _parseDateInput

# 需要导入模块: import pendulum [as 别名]
# 或者: from pendulum import datetime [as 别名]
def _parseDateInput(cls, date):
        """Verify that the given string is a valid date formatted as
        YYYY-MM-DD. Also, the API seems to go back until 2014-10-04,
        so we will check that the input is not a date earlier than that.
        In case of failure, throws a ValueError exception.
        """
        date = date.lower()

        if date in cls._FUZZY_DAYS:
            date = cls._EnglishDateToDate(date)

        elif date.replace("-", "").isdigit():
            try:
                parsed_date = pendulum.from_format(date, "YYYY-MM-DD")
            except:
                raise ValueError("Incorrect date format, should be YYYY-MM-DD")

            # The current API goes back until 2014-10-04. Is it in range?
            if parsed_date < pendulum.datetime(2014, 10, 4):
                raise ValueError("I can only go back until 2014-10-04")
        else:
            raise ValueError("Date is not valid")

        return cls._stripDateSeparators(date) 
开发者ID:oddluck,项目名称:limnoria-plugins,代码行数:26,代码来源:plugin.py

示例4: test_timezone_awareness

# 需要导入模块: import pendulum [as 别名]
# 或者: from pendulum import datetime [as 别名]
def test_timezone_awareness(self):
        naive_datetime = DEFAULT_DATE.replace(tzinfo=None)

        # check ti without dag (just for bw compat)
        op_no_dag = DummyOperator(task_id='op_no_dag')
        ti = TI(task=op_no_dag, execution_date=naive_datetime)

        self.assertEqual(ti.execution_date, DEFAULT_DATE)

        # check with dag without localized execution_date
        dag = DAG('dag', start_date=DEFAULT_DATE)
        op1 = DummyOperator(task_id='op_1')
        dag.add_task(op1)
        ti = TI(task=op1, execution_date=naive_datetime)

        self.assertEqual(ti.execution_date, DEFAULT_DATE)

        # with dag and localized execution_date
        tzinfo = pendulum.timezone("Europe/Amsterdam")
        execution_date = timezone.datetime(2016, 1, 1, 1, 0, 0, tzinfo=tzinfo)
        utc_date = timezone.convert_to_utc(execution_date)
        ti = TI(task=op1, execution_date=execution_date)
        self.assertEqual(ti.execution_date, utc_date) 
开发者ID:apache,项目名称:airflow,代码行数:25,代码来源:test_taskinstance.py

示例5: test_mark_non_runnable_task_as_success

# 需要导入模块: import pendulum [as 别名]
# 或者: from pendulum import datetime [as 别名]
def test_mark_non_runnable_task_as_success(self):
        """
        test that running task with mark_success param update task state
        as SUCCESS without running task despite it fails dependency checks.
        """
        non_runnable_state = (
            set(State.task_states) - RUNNABLE_STATES - set(State.SUCCESS)).pop()
        dag = models.DAG(dag_id='test_mark_non_runnable_task_as_success')
        task = DummyOperator(
            task_id='test_mark_non_runnable_task_as_success_op',
            dag=dag,
            pool='test_pool',
            owner='airflow',
            start_date=timezone.datetime(2016, 2, 1, 0, 0, 0))
        ti = TI(
            task=task, execution_date=timezone.utcnow(), state=non_runnable_state)
        # TI.run() will sync from DB before validating deps.
        with create_session() as session:
            session.add(ti)
            session.commit()
        ti.run(mark_success=True)
        self.assertEqual(ti.state, State.SUCCESS) 
开发者ID:apache,项目名称:airflow,代码行数:24,代码来源:test_taskinstance.py

示例6: test_ti_updates_with_task

# 需要导入模块: import pendulum [as 别名]
# 或者: from pendulum import datetime [as 别名]
def test_ti_updates_with_task(self, session=None):
        """
        test that updating the executor_config propogates to the TaskInstance DB
        """
        with models.DAG(dag_id='test_run_pooling_task') as dag:
            task = DummyOperator(task_id='test_run_pooling_task_op', owner='airflow',
                                 executor_config={'foo': 'bar'},
                                 start_date=timezone.datetime(2016, 2, 1, 0, 0, 0))
        ti = TI(
            task=task, execution_date=timezone.utcnow())

        ti.run(session=session)
        tis = dag.get_task_instances()
        self.assertEqual({'foo': 'bar'}, tis[0].executor_config)
        with models.DAG(dag_id='test_run_pooling_task') as dag:
            task2 = DummyOperator(task_id='test_run_pooling_task_op', owner='airflow',
                                  executor_config={'bar': 'baz'},
                                  start_date=timezone.datetime(2016, 2, 1, 0, 0, 0))

        ti = TI(
            task=task2, execution_date=timezone.utcnow())
        ti.run(session=session)
        tis = dag.get_task_instances()
        self.assertEqual({'bar': 'baz'}, tis[1].executor_config) 
开发者ID:apache,项目名称:airflow,代码行数:26,代码来源:test_taskinstance.py

示例7: test_run_pooling_task_with_mark_success

# 需要导入模块: import pendulum [as 别名]
# 或者: from pendulum import datetime [as 别名]
def test_run_pooling_task_with_mark_success(self):
        """
        test that running task in an existing pool with mark_success param
        update task state as SUCCESS without running task
        despite it fails dependency checks.
        """
        dag = models.DAG(dag_id='test_run_pooling_task_with_mark_success')
        task = DummyOperator(
            task_id='test_run_pooling_task_with_mark_success_op',
            dag=dag,
            pool='test_pool',
            owner='airflow',
            start_date=timezone.datetime(2016, 2, 1, 0, 0, 0))
        ti = TI(
            task=task, execution_date=timezone.utcnow())
        ti.run(mark_success=True)
        self.assertEqual(ti.state, State.SUCCESS) 
开发者ID:apache,项目名称:airflow,代码行数:19,代码来源:test_taskinstance.py

示例8: test_run_pooling_task_with_skip

# 需要导入模块: import pendulum [as 别名]
# 或者: from pendulum import datetime [as 别名]
def test_run_pooling_task_with_skip(self):
        """
        test that running task which returns AirflowSkipOperator will end
        up in a SKIPPED state.
        """

        def raise_skip_exception():
            raise AirflowSkipException

        dag = models.DAG(dag_id='test_run_pooling_task_with_skip')
        task = PythonOperator(
            task_id='test_run_pooling_task_with_skip',
            dag=dag,
            python_callable=raise_skip_exception,
            owner='airflow',
            start_date=timezone.datetime(2016, 2, 1, 0, 0, 0))
        ti = TI(
            task=task, execution_date=timezone.utcnow())
        ti.run()
        self.assertEqual(State.SKIPPED, ti.state) 
开发者ID:apache,项目名称:airflow,代码行数:22,代码来源:test_taskinstance.py

示例9: test_next_retry_datetime_short_intervals

# 需要导入模块: import pendulum [as 别名]
# 或者: from pendulum import datetime [as 别名]
def test_next_retry_datetime_short_intervals(self):
        delay = datetime.timedelta(seconds=1)
        max_delay = datetime.timedelta(minutes=60)

        dag = models.DAG(dag_id='fail_dag')
        task = BashOperator(
            task_id='task_with_exp_backoff_and_short_time_interval',
            bash_command='exit 1',
            retries=3,
            retry_delay=delay,
            retry_exponential_backoff=True,
            max_retry_delay=max_delay,
            dag=dag,
            owner='airflow',
            start_date=timezone.datetime(2016, 2, 1, 0, 0, 0))
        ti = TI(
            task=task, execution_date=DEFAULT_DATE)
        ti.end_date = pendulum.instance(timezone.utcnow())

        date = ti.next_retry_datetime()
        # between 1 * 2^0.5 and 1 * 2^1 (15 and 30)
        period = ti.end_date.add(seconds=15) - ti.end_date.add(seconds=1)
        self.assertTrue(date in period) 
开发者ID:apache,项目名称:airflow,代码行数:25,代码来源:test_taskinstance.py

示例10: test_xcom_push_flag

# 需要导入模块: import pendulum [as 别名]
# 或者: from pendulum import datetime [as 别名]
def test_xcom_push_flag(self):
        """
        Tests the option for Operators to push XComs
        """
        value = 'hello'
        task_id = 'test_no_xcom_push'
        dag = models.DAG(dag_id='test_xcom')

        # nothing saved to XCom
        task = PythonOperator(
            task_id=task_id,
            dag=dag,
            python_callable=lambda: value,
            do_xcom_push=False,
            owner='airflow',
            start_date=datetime.datetime(2017, 1, 1)
        )
        ti = TI(task=task, execution_date=datetime.datetime(2017, 1, 1))
        ti.run()
        self.assertEqual(
            ti.xcom_pull(
                task_ids=task_id, key=models.XCOM_RETURN_KEY
            ),
            None
        ) 
开发者ID:apache,项目名称:airflow,代码行数:27,代码来源:test_taskinstance.py

示例11: test_post_execute_hook

# 需要导入模块: import pendulum [as 别名]
# 或者: from pendulum import datetime [as 别名]
def test_post_execute_hook(self):
        """
        Test that post_execute hook is called with the Operator's result.
        The result ('error') will cause an error to be raised and trapped.
        """

        class TestError(Exception):
            pass

        class TestOperator(PythonOperator):
            def post_execute(self, context, result=None):
                if result == 'error':
                    raise TestError('expected error.')

        dag = models.DAG(dag_id='test_post_execute_dag')
        task = TestOperator(
            task_id='test_operator',
            dag=dag,
            python_callable=lambda: 'error',
            owner='airflow',
            start_date=timezone.datetime(2017, 2, 1))
        ti = TI(task=task, execution_date=timezone.utcnow())

        with self.assertRaises(TestError):
            ti.run() 
开发者ID:apache,项目名称:airflow,代码行数:27,代码来源:test_taskinstance.py

示例12: test_email_alert

# 需要导入模块: import pendulum [as 别名]
# 或者: from pendulum import datetime [as 别名]
def test_email_alert(self, mock_send_email):
        dag = models.DAG(dag_id='test_failure_email')
        task = BashOperator(
            task_id='test_email_alert',
            dag=dag,
            bash_command='exit 1',
            start_date=DEFAULT_DATE,
            email='to')

        ti = TI(task=task, execution_date=datetime.datetime.now())

        try:
            ti.run()
        except AirflowException:
            pass

        (email, title, body), _ = mock_send_email.call_args
        self.assertEqual(email, 'to')
        self.assertIn('test_email_alert', title)
        self.assertIn('test_email_alert', body)
        self.assertIn('Try 1', body) 
开发者ID:apache,项目名称:airflow,代码行数:23,代码来源:test_taskinstance.py

示例13: test_email_alert_with_config

# 需要导入模块: import pendulum [as 别名]
# 或者: from pendulum import datetime [as 别名]
def test_email_alert_with_config(self, mock_send_email):
        dag = models.DAG(dag_id='test_failure_email')
        task = BashOperator(
            task_id='test_email_alert_with_config',
            dag=dag,
            bash_command='exit 1',
            start_date=DEFAULT_DATE,
            email='to')

        ti = TI(
            task=task, execution_date=datetime.datetime.now())

        opener = mock_open(read_data='template: {{ti.task_id}}')
        with patch('airflow.models.taskinstance.open', opener, create=True):
            try:
                ti.run()
            except AirflowException:
                pass

        (email, title, body), _ = mock_send_email.call_args
        self.assertEqual(email, 'to')
        self.assertEqual('template: test_email_alert_with_config', title)
        self.assertEqual('template: test_email_alert_with_config', body) 
开发者ID:apache,项目名称:airflow,代码行数:25,代码来源:test_taskinstance.py

示例14: test_execute_callback

# 需要导入模块: import pendulum [as 别名]
# 或者: from pendulum import datetime [as 别名]
def test_execute_callback(self):
        called = False

        def on_execute_callable(context):
            nonlocal called
            called = True
            self.assertEqual(
                context['dag_run'].dag_id,
                'test_dagrun_execute_callback'
            )

        dag = DAG('test_execute_callback', start_date=DEFAULT_DATE,
                  end_date=DEFAULT_DATE + datetime.timedelta(days=10))
        task = DummyOperator(task_id='op', email='test@test.test',
                             on_execute_callback=on_execute_callable,
                             dag=dag)
        ti = TI(task=task, execution_date=datetime.datetime.now())
        ti.state = State.RUNNING
        session = settings.Session()
        session.merge(ti)
        session.commit()
        ti._run_raw_task()
        assert called
        ti.refresh_from_db()
        assert ti.state == State.SUCCESS 
开发者ID:apache,项目名称:airflow,代码行数:27,代码来源:test_taskinstance.py

示例15: test_does_not_retry_on_airflow_fail_exception

# 需要导入模块: import pendulum [as 别名]
# 或者: from pendulum import datetime [as 别名]
def test_does_not_retry_on_airflow_fail_exception(self):
        def fail():
            raise AirflowFailException("hopeless")

        dag = models.DAG(dag_id='test_does_not_retry_on_airflow_fail_exception')
        task = PythonOperator(
            task_id='test_raise_airflow_fail_exception',
            dag=dag,
            python_callable=fail,
            owner='airflow',
            start_date=timezone.datetime(2016, 2, 1, 0, 0, 0),
            retries=1
        )
        ti = TI(task=task, execution_date=timezone.utcnow())
        try:
            ti.run()
        except AirflowFailException:
            pass  # expected
        self.assertEqual(State.FAILED, ti.state) 
开发者ID:apache,项目名称:airflow,代码行数:21,代码来源:test_taskinstance.py


注:本文中的pendulum.datetime方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。