Add UUID fixture

stix2.1
Greg Back 2017-01-18 16:32:52 -08:00
parent 439211082a
commit 022f344b94
1 changed files with 24 additions and 0 deletions

View File

@ -1,6 +1,7 @@
"""Tests for the stix2 library"""
import datetime
import uuid
import pytest
import pytz
@ -24,6 +25,29 @@ def clock(monkeypatch):
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', [
(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'),