Add UUID fixture
parent
439211082a
commit
022f344b94
|
@ -1,6 +1,7 @@
|
||||||
"""Tests for the stix2 library"""
|
"""Tests for the stix2 library"""
|
||||||
|
|
||||||
import datetime
|
import datetime
|
||||||
|
import uuid
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
import pytz
|
import pytz
|
||||||
|
@ -24,6 +25,29 @@ def clock(monkeypatch):
|
||||||
monkeypatch.setattr(datetime, 'datetime', mydatetime)
|
monkeypatch.setattr(datetime, 'datetime', mydatetime)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def uuid4(monkeypatch):
|
||||||
|
def wrapper():
|
||||||
|
data = [0]
|
||||||
|
|
||||||
|
def wrapped():
|
||||||
|
data[0] += 1
|
||||||
|
return "00000000-0000-0000-0000-00000000%04x" % data[0]
|
||||||
|
|
||||||
|
return wrapped
|
||||||
|
monkeypatch.setattr(uuid, "uuid4", wrapper())
|
||||||
|
|
||||||
|
|
||||||
|
def test_my_uuid4_fixture(uuid4):
|
||||||
|
assert uuid.uuid4() == "00000000-0000-0000-0000-000000000001"
|
||||||
|
assert uuid.uuid4() == "00000000-0000-0000-0000-000000000002"
|
||||||
|
assert uuid.uuid4() == "00000000-0000-0000-0000-000000000003"
|
||||||
|
for _ in range(256):
|
||||||
|
uuid.uuid4()
|
||||||
|
assert uuid.uuid4() == "00000000-0000-0000-0000-000000000104"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('dt,timestamp', [
|
@pytest.mark.parametrize('dt,timestamp', [
|
||||||
(datetime.datetime(2017, 1, 1, tzinfo=pytz.utc), '2017-01-01T00:00:00Z'),
|
(datetime.datetime(2017, 1, 1, tzinfo=pytz.utc), '2017-01-01T00:00:00Z'),
|
||||||
(amsterdam.localize(datetime.datetime(2017, 1, 1)), '2016-12-31T23:00:00Z'),
|
(amsterdam.localize(datetime.datetime(2017, 1, 1)), '2016-12-31T23:00:00Z'),
|
||||||
|
|
Loading…
Reference in New Issue