From 5874309d9c026e9c701f73a34079585148fff95a Mon Sep 17 00:00:00 2001 From: evilchili Date: Sat, 6 Jan 2024 12:18:44 -0800 Subject: [PATCH] adding tests --- test/test_datasources.py | 49 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 test/test_datasources.py diff --git a/test/test_datasources.py b/test/test_datasources.py new file mode 100644 index 0000000..a17f5a1 --- /dev/null +++ b/test/test_datasources.py @@ -0,0 +1,49 @@ +from io import StringIO + +from random_sets import datasources +from pprint import pprint as print + +fixture_metadata = """ +metadata: + headers: + - Header 1 + - Header 2 + - Header 3 + die: 10 + frequencies: + default: + Option 1: 0.3 + Option 2: 0.5 + Option 3: 0.2 + nondefault: + Option 1: 0.0 + Option 2: 0.1 + Option 3: 0.9 +""" + +fixture_source = """ +Option 1: + - choice 1: description 1 + - choice 2: description 2 + - choice 3: description 3 +Option 2: + - choice 1: description 4 + - choice 2: description 5 + - choice 3: description 6 +Option 3: + - choice 1: description 7 + - choice 2: description 8 + - choice 3: description 9 +""" + + +def test_datasource_random_values(): + fixture = StringIO(fixture_metadata + fixture_source) + ds = datasources.DataSource(fixture) + randvals = ds.random_values(count=2) + + # we asked for two random values + assert len(randvals) == 2 + + # each value has an "Option", a "choice", and a "description" + assert len(randvals[0]) == 3