Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def write_backup_and_wal_files(what):
for bb, wals in what.items():
if bb:
bb_path = os.path.join(basebackup_storage_path, bb)
date_parts = [int(part) for part in bb.replace("_", "-").split("-")]
start_time = datetime.datetime(*date_parts, tzinfo=datetime.timezone.utc)
with open(bb_path, "wb") as fp:
fp.write(b"something")
with open(bb_path + ".metadata", "w") as fp:
json.dump({
"start-wal-segment": wals[0],
"start-time": start_time.isoformat(),
}, fp)
for wal in wals:
with open(os.path.join(wal_storage_path, wal), "wb") as fp:
fp.write(b"something")
import six
from faker import Faker
from faker.providers.date_time import Provider as DatetimeProvider
from faker.providers.date_time.pl_PL import Provider as PlProvider
from faker.providers.date_time.ar_AA import Provider as ArProvider
from faker.providers.date_time.ar_EG import Provider as EgProvider
from faker.providers.date_time.hy_AM import Provider as HyAmProvider
from faker.providers.date_time.ta_IN import Provider as TaInProvider
def is64bit():
return sys.maxsize > 2**32
class UTC(tzinfo):
"""
UTC implementation taken from Python's docs.
"""
def __repr__(self):
return ""
def utcoffset(self, dt):
return timedelta(0)
def tzname(self, dt):
return "UTC"
def dst(self, dt):
return timedelta(0)
def test_weeks_single_iso(self):
unit = 'weeks'
range_from = -1
range_to = -1
epoch = curator.datetime_to_epoch(datetime(2017, 4, 3, 22, 50, 17))
start = curator.datetime_to_epoch(datetime(2017, 3, 27, 0, 0, 0))
end = curator.datetime_to_epoch(datetime(2017, 4, 2, 23, 59, 59))
self.assertEqual((start,end),
curator.date_range(unit, range_from, range_to, epoch=epoch,
week_starts_on='monday')
)
for i in range(1, 4):
note.insert(
content='note %s' % i,
timestamp=datetime.date(2014, 1, i),
user='charlie')
notes = sorted(note.all(), key=operator.itemgetter('id'))
self.assertEqual(notes[0], {
'content': 'note 1',
'id': 1,
'timestamp': datetime.datetime(2014, 1, 1),
'user': 'charlie'})
self.assertEqual(notes[-1], {
'content': 'note 3',
'id': 3,
'timestamp': datetime.datetime(2014, 1, 3),
'user': 'charlie'})
user.insert(username='mickey')
note.update(user='mickey', id=3, columns=['id'])
self.assertEqual(note.find(user='charlie').count(), 2)
self.assertEqual(note.find(user='mickey').count(), 1)
category = self.dataset['category']
category.insert(name='c1')
c1 = category.find_one(name='c1')
self.assertEqual(c1, {'id': 1, 'name': 'c1', 'parent': None})
category.insert(name='c2', parent=1)
c2 = category.find_one(parent=1)
self.assertEqual(c2, {'id': 2, 'name': 'c2', 'parent': 1})
def test_add_occupied_timewindow(self, alchemy_store, fact, alchemy_fact):
"""
Make sure that passing a fact with a timewindow that already has a fact raises error.
"""
fact.start = alchemy_fact.start - datetime.timedelta(days=4)
fact.end = alchemy_fact.start + datetime.timedelta(minutes=15)
with pytest.raises(ValueError):
alchemy_store.facts._add(fact)
frozen_time.tick(datetime.timedelta(seconds=11))
start = timeit.default_timer()
with pytest.raises(MessageReceiveTimeout) as error_context:
core.receive_message('test_expired_message')
elapsed = timeit.default_timer() - start
assert 0 < elapsed < 0.1 # This shouldn't actually take 3 seconds, it should be instant
assert 'expired' in error_context.value.args[0]
frozen_time.tick(datetime.timedelta(seconds=1))
request_id = 19
core.send_message('test_expired_message', request_id, {}, {'test': 'payload'})
frozen_time.tick(datetime.timedelta(seconds=10))
start = timeit.default_timer()
response = core.receive_message('test_expired_message')
elapsed = timeit.default_timer() - start
assert 0 < elapsed < 0.1
assert response[0] == request_id
types = [str]
if not PY3: # pragma: nocover
types.append(unicode_)
for type_ in types:
inputs = {
type_('@pBigInt'): ctds.Parameter(12345, output=True),
type_('@pVarChar'): ctds.Parameter(
unicode_('hello world, how\'s it going! '),
output=True
),
type_('@pVarBinary'): ctds.Parameter(ctds.SqlVarBinary(None, size=32), output=True),
type_('@pFloat'): ctds.Parameter(1.23, output=True),
type_('@pDateTime'): datetime(2011, 11, 5, 12, 12, 12),
type_('@pDateTimeOut'): ctds.Parameter(datetime(2011, 11, 5, 12, 12, 12), output=True),
type_('@pDateTime2'): datetime(2011, 11, 5, 12, 12, 12, 999999),
type_('@pDateTime2Out'): ctds.Parameter(datetime.utcnow(), output=True),
type_('@pDate'): date(2011, 11, 5),
type_('@pDateOut'): ctds.Parameter(date.today(), output=True),
type_('@pTime'): time(12, 12, 12, 123456),
type_('@pTimeOut'): ctds.Parameter(datetime.utcnow().time(), output=True),
}
outputs = cursor.callproc(sproc, inputs)
self.assertNotEqual(id(outputs[type_('@pBigInt')]), id(inputs[type_('@pBigInt')]))
self.assertNotEqual(id(outputs[type_('@pVarChar')]), id(inputs[type_('@pVarChar')]))
self.assertNotEqual(id(outputs[type_('@pVarBinary')]), id(inputs[type_('@pVarBinary')]))
self.assertEqual(id(outputs[type_('@pDateTime')]), id(inputs[type_('@pDateTime')]))
self.assertEqual(id(outputs[type_('@pDateTime2')]), id(inputs[type_('@pDateTime2')]))
self.assertEqual(id(outputs[type_('@pDate')]), id(inputs[type_('@pDate')]))
self.assertEqual(id(outputs[type_('@pTime')]), id(inputs[type_('@pTime')]))
self.assertEqual(
outputs[type_('@pBigInt')],
def test_get_active_organization_counts_in_interval_quarter(self):
self._fill_calendar_range(datetime.date(2018, 12, 1), datetime.date(2020, 1, 1))
self._save_ehr_receipt(org=self.org_foo_a, receipt_time=datetime.datetime(2019, 5, 1))
self._save_ehr_receipt(org=self.org_bar_a, receipt_time=datetime.datetime(2019, 5, 1))
self._save_ehr_receipt(org=self.org_foo_a, receipt_time=datetime.datetime(2019, 11, 1))
results = self.ehr_receipt_dao.get_active_organization_counts_in_interval(
start_date=datetime.datetime(2019, 1, 1), end_date=datetime.datetime(2020, 1, 1), interval=INTERVAL_QUARTER
)
self.assertEqual(
[(r["start_date"], r["active_organization_count"]) for r in results],
[
(datetime.date(2019, 1, 1), 0),
(datetime.date(2019, 4, 1), 2),
(datetime.date(2019, 7, 1), 0),
(datetime.date(2019, 10, 1), 1),
(datetime.date(2020, 1, 1), 0),
],
def make_batch_and_line(sku, batch_qty, line_qty):
return (
Batch("batch-001", sku, batch_qty, eta=date.today()),
OrderLine("order-123", sku, line_qty)
)
def atest_root(kernel32_idb):
root = idb.netnode.get_nodeid(kernel32_idb, 'Root Node')
assert idb.netnode.get_int(kernel32_idb, root, 'A', idb.netnode.ROOT_INDEX.VERSION) == 695
assert idb.netnode.get_string(kernel32_idb, root, 'S', idb.netnode.ROOT_INDEX.VERSION_STRING) == '6.95'
assert idb.netnode.get_int(kernel32_idb, root, 'A', idb.netnode.ROOT_INDEX.OPEN_COUNT) == 1
ts = idb.netnode.get_int(kernel32_idb, root, 'A', idb.netnode.ROOT_INDEX.CREATED)
ts = datetime.datetime.utcfromtimestamp(ts)
assert ts.isoformat() == '2017-06-20T22:31:34'
assert idb.netnode.get_int(kernel32_idb, root, 'A', idb.netnode.ROOT_INDEX.CRC) == 0xdf9bdf12
md5 = idb.netnode.get_bytes(kernel32_idb, root, 'S', idb.netnode.ROOT_INDEX.MD5)
md5 = binascii.hexlify(md5).decode('ascii')
assert md5 == '00bf1bf1b779ce1af41371426821e0c2'