datetime.

Here are the examples of the python api datetime. taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

117 Examples 7

Example 101

Project: luci-py Source File: gitiles_test.py
  def test_parse_time_with_negative_timezone(self):
    time_str = 'Fri Nov 07 17:09:03 2014 -01:00'
    expected = datetime.datetime(2014, 11, 07, 18, 9, 3)
    actual = gitiles.parse_time(time_str)
    self.assertEqual(expected, actual)

Example 102

Project: luci-py Source File: task_to_run_test.py
Function: set_up
  def setUp(self):
    super(TaskToRunApiTest, self).setUp()
    self.now = datetime.datetime(2014, 01, 02, 03, 04, 05, 06)

Example 103

Project: allura Source File: test_globals.py
    @patch('allura.lib.app_globals.M', autospec=True)
    @patch('allura.lib.app_globals.datetime', autospec=True)
    def test_lookup(self, dt_mock, M):
        dt_mock.datetime.utcnow.side_effect = [
            dt.datetime(2015, 02, 05, 11, 32),
            dt.datetime(2015, 02, 05, 11, 34),
        ]
        ret = M.Neighborhood.query.get.return_value
        cache = NeighborhoodCache(30)
        assert_equal(cache._data, {})

        n = cache._lookup('/p/')
        M.Neighborhood.query.get.assert_called_once_with(url_prefix='/p/')
        assert_equal(n, ret)
        assert_equal(cache._data, {'/p/': {
            'object': ret,
            'ts': dt.datetime(2015, 02, 05, 11, 32),
        }})

        # hits mongo every time
        n = cache._lookup('/p/')
        assert_equal(M.Neighborhood.query.get.call_count, 2)
        assert_equal(n, ret)
        assert_equal(cache._data, {'/p/': {
            'object': ret,
            'ts': dt.datetime(2015, 02, 05, 11, 34),
        }})

Example 104

Project: allura Source File: test_globals.py
    @patch('allura.lib.app_globals.M', autospec=True)
    @patch('allura.lib.app_globals.datetime', autospec=True)
    def test_get(self, dt_mock, M):
        dt_mock.datetime.utcnow.side_effect = [
            dt.datetime(2015, 02, 05, 11, 32),
            dt.datetime(2015, 02, 05, 11, 34),
        ]
        ret = M.Neighborhood.query.get.return_value
        cache = NeighborhoodCache(30)
        cache._expired = Mock(return_value=False)

        n = cache.get('/p/')
        M.Neighborhood.query.get.assert_called_once_with(url_prefix='/p/')
        assert_equal(n, ret)

        # don't hit mongo second time
        n = cache.get('/p/')
        assert_equal(M.Neighborhood.query.get.call_count, 1)
        assert_equal(n, ret)

        # and hits if cache is expired
        cache._expired.return_value = True
        n = cache.get('/p/')
        assert_equal(M.Neighborhood.query.get.call_count, 2)
        assert_equal(n, ret)

Example 105

Project: allura Source File: test_plugin.py
    def test_get_last_password_updated(self):
        user = Mock()
        user.last_password_updated = dt.datetime(2014, 06, 04, 13, 13, 13)
        upd = self.provider.get_last_password_updated(user)
        assert_equal(upd, user.last_password_updated)

Example 106

Project: allura Source File: test_utils.py
def test_DateJSONEncoder():
    data = {'message': u'Hi!',
            'date': dt.datetime(2015, 01, 30, 13, 13, 13)}
    result = json.dumps(data, cls=utils.DateJSONEncoder)
    assert_equal(result, '{"date": "2015-01-30T13:13:13Z", "message": "Hi!"}')

Example 107

Project: acousticbrainz-server Source File: test_stats.py
    def test_write_and_get_statistics_data(self):
        stats1 = {"lowlevel-lossy": 10, "lowlevel-lossy-unique": 6,
                  "lowlevel-lossless": 15, "lowlevel-lossless-unique": 10,
                  "lowlevel-total": 25, "lowlevel-total-unique": 16}
        date1 = datetime.datetime(2016, 01, 10, 00, 00, tzinfo=pytz.utc)
        stats2 = {"lowlevel-lossy": 15, "lowlevel-lossy-unique": 10,
                  "lowlevel-lossless": 20, "lowlevel-lossless-unique": 10,
                  "lowlevel-total": 35, "lowlevel-total-unique": 20}
        date2 = datetime.datetime(2016, 01, 11, 00, 00, tzinfo=pytz.utc)
        with db.engine.connect() as connection:
            db.stats._write_stats(connection, date1, stats1)
            db.stats._write_stats(connection, date2, stats2)

        data = db.stats.load_statistics_data()
        self.assertEqual(2, len(data))
        expected_data = [
            {"collected": date1, "stats": stats1},
            {"collected": date2, "stats": stats2}
        ]
        self.assertEqual(list(expected_data), list(data))

Example 108

Project: acousticbrainz-server Source File: test_stats.py
    def test_format_statistics_for_hicharts(self):
        """Format statistics for display on history graph"""

        stats1 = {"lowlevel-lossy": 10, "lowlevel-lossy-unique": 6,
                  "lowlevel-lossless": 15, "lowlevel-lossless-unique": 10,
                  "lowlevel-total": 25, "lowlevel-total-unique": 16}
        date1 = datetime.datetime(2016, 01, 10, 00, 00, tzinfo=pytz.utc)
        stats2 = {"lowlevel-lossy": 15, "lowlevel-lossy-unique": 10,
                  "lowlevel-lossless": 20, "lowlevel-lossless-unique": 10,
                  "lowlevel-total": 35, "lowlevel-total-unique": 20}
        date2 = datetime.datetime(2016, 01, 11, 00, 00, tzinfo=pytz.utc)
        data = [
            {"collected": date1, "stats": stats1},
            {"collected": date2, "stats": stats2}
        ]

        formatted = db.stats.format_statistics_for_highcharts(data)
        expected_formatted = [
            {'data': [[1452384000000, 15], [1452470400000, 20]], 'name': 'Lossless (all)'},
            {'data': [[1452384000000, 10], [1452470400000, 10]], 'name': 'Lossless (unique)'},
            {'data': [[1452384000000, 10], [1452470400000, 15]], 'name': 'Lossy (all)'},
            {'data': [[1452384000000, 6], [1452470400000, 10]], 'name': 'Lossy (unique)'},
            {'data': [[1452384000000, 25], [1452470400000, 35]], 'name': 'Total (all)'},
            {'data': [[1452384000000, 16], [1452470400000, 20]], 'name': 'Total (unique)'}]
        self.assertEqual(sorted(expected_formatted), sorted(formatted))

Example 109

Project: acousticbrainz-server Source File: test_stats.py
    def test_get_statistics_data_limit(self):
        stats1 = {"lowlevel-lossy": 10, "lowlevel-lossy-unique": 6,
                  "lowlevel-lossless": 15, "lowlevel-lossless-unique": 10,
                  "lowlevel-total": 25, "lowlevel-total-unique": 16}
        date1 = datetime.datetime(2016, 01, 10, 00, 00, tzinfo=pytz.utc)
        stats2 = {"lowlevel-lossy": 15, "lowlevel-lossy-unique": 10,
                  "lowlevel-lossless": 20, "lowlevel-lossless-unique": 10,
                  "lowlevel-total": 35, "lowlevel-total-unique": 20}
        date2 = datetime.datetime(2016, 01, 11, 00, 00, tzinfo=pytz.utc)
        with db.engine.connect() as connection:
            db.stats._write_stats(connection, date1, stats1)
            db.stats._write_stats(connection, date2, stats2)

        # If we ask for just 1 stats, it's the one that's later in time
        data = db.stats.load_statistics_data(1)
        self.assertEqual(1, len(data))
        expected_data = [
            {"collected": date2, "stats": stats2}
        ]
        self.assertEqual(list(expected_data), list(data))

Example 110

Project: tipfy Source File: i18n_test.py
    def test_format_date_no_format(self):
        value = datetime.datetime(2009, 11, 10, 16, 36, 05)
        self.assertEqual(i18n.format_date(value), u'Nov 10, 2009')

Example 111

Project: tipfy Source File: i18n_test.py
    def test_format_datetime_no_format(self):
        value = datetime.datetime(2009, 11, 10, 16, 36, 05)
        self.assertEqual(i18n.format_datetime(value), u'Nov 10, 2009 4:36:05 PM')

Example 112

Project: tipfy Source File: i18n_test.py
    def test_format_time_no_format(self):
        value = datetime.datetime(2009, 11, 10, 16, 36, 05)
        self.assertEqual(i18n.format_time(value), u'4:36:05 PM')

Example 113

Project: remo Source File: test_models.py
    def test_get_absolute_url(self):
        report = NGReportFactory.create(
            report_date=datetime.date(2012, 01, 01), id=9999)
        eq_(report.get_absolute_url(),
            '/u/{0}/r/2012/January/1/9999/'.format(report.user.userprofile.display_name))

Example 114

Project: remo Source File: test_models.py
    def test_get_absolute_edit_url(self):
        report = NGReportFactory.create(
            report_date=datetime.date(2012, 01, 01), id=9999)
        eq_(report.get_absolute_edit_url(),
            '/u/{0}/r/2012/January/1/9999/edit/'.format(report.user.userprofile.display_name))

Example 115

Project: remo Source File: test_models.py
    def test_get_absolute_delete_url(self):
        report = NGReportFactory.create(
            report_date=datetime.date(2012, 01, 01), id=9999)
        eq_(report.get_absolute_delete_url(),
            '/u/{0}/r/2012/January/1/9999/delete/'.format(report.user.userprofile.display_name))

Example 116

Project: remo Source File: test_views.py
    def test_old_report_redirect(self):
        """Test old report url redirects to list of reports for that month."""
        user = UserFactory.create(groups=['Rep'])
        report_date = datetime.date(2011, 01, 05)

Example 117

Project: dodai-compute Source File: fake.py
Function: init
    def __init__(self):
        self.images = {}
        # NOTE(justinsb): The OpenStack API can't upload an image?
        # So, make sure we've got one..
        timestamp = datetime.datetime(2011, 01, 01, 01, 02, 03)
See More Examples - Go to Next Page
Page 1 Page 2 Page 3 Selected