-
Notifications
You must be signed in to change notification settings - Fork 191
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
107 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import random | ||
from functools import partial | ||
|
||
from petl.util.random import randomseed, randomtable, RandomTable, dummytable | ||
|
||
|
||
def test_randomseed(): | ||
s = randomseed() | ||
|
||
assert isinstance(s, str) | ||
assert s != "" | ||
|
||
|
||
def test_randomtable(): | ||
columns, rows = 3, 10 | ||
table = randomtable(columns, rows) | ||
|
||
assert len(table[0]) == columns | ||
assert len(table) == rows + 1 | ||
|
||
|
||
def test_randomtable_class(): | ||
columns, rows = 4, 60 | ||
table = RandomTable(numflds=columns, numrows=rows) | ||
|
||
assert len(table[0]) == columns | ||
assert len(table) == rows + 1 | ||
|
||
|
||
def test_dummytable_custom_fields(): | ||
columns = ( | ||
('count', partial(random.randint, 0, 100)), | ||
('pet', partial(random.choice, ('dog', 'cat', 'cow'))), | ||
('color', partial(random.choice, ('yellow', 'orange', 'brown'))), | ||
('value', random.random) | ||
) | ||
rows = 35 | ||
|
||
table = dummytable( | ||
numrows=rows, | ||
fields=columns, | ||
) | ||
assert len(table[0]) == 4 | ||
assert len(table) == rows + 1 | ||
|
||
|
||
def test_dummytable_no_seed(): | ||
rows = 35 | ||
|
||
table = dummytable( | ||
numrows=rows, | ||
) | ||
assert len(table[0]) == 3 | ||
assert len(table) == rows + 1 | ||
|
||
|
||
def test_dummytable_int_seed(): | ||
rows = 35 | ||
|
||
table = dummytable( | ||
numrows=rows, | ||
seed=42 | ||
) | ||
assert len(table[0]) == 3 | ||
assert len(table) == rows + 1 | ||
|
||
|
||
def test_dummytable_class(): | ||
rows = 70 | ||
table = dummytable(numrows=rows) | ||
|
||
assert len(table) == rows + 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters