-
Notifications
You must be signed in to change notification settings - Fork 193
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Resolve DeprecationWarning: Seeding based on hashing #656
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
import random as pyrandom | ||
Check warning Code scanning / Pylint (reported by Codacy) Missing module docstring Warning test
Missing module docstring
|
||
import time | ||
from functools import partial | ||
|
||
from petl.util.random import randomseed, randomtable, RandomTable, dummytable, DummyTable | ||
|
||
|
||
def test_randomseed(): | ||
|
||
""" | ||
Ensure that randomseed provides a non-empty string that changes. | ||
""" | ||
seed_1 = randomseed() | ||
time.sleep(1) | ||
seed_2 = randomseed() | ||
|
||
assert isinstance(seed_1, str) | ||
|
||
assert seed_1 != "" | ||
|
||
assert seed_1 != seed_2 | ||
|
||
|
||
|
||
def test_randomtable(): | ||
|
||
""" | ||
Ensure that randomtable provides a table with the right number of rows and columns. | ||
""" | ||
columns, rows = 3, 10 | ||
table = randomtable(columns, rows) | ||
|
||
assert len(table[0]) == columns | ||
Check notice Code scanning / Semgrep (reported by Codacy) The application was found using assert in non-test code. Note test
The application was found using assert in non-test code.
Check warning Code scanning / Bandit (reported by Codacy) Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Warning test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
|
||
assert len(table) == rows + 1 | ||
Check warning Code scanning / Bandit (reported by Codacy) Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Warning test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Check notice Code scanning / Semgrep (reported by Codacy) The application was found using assert in non-test code. Note test
The application was found using assert in non-test code.
|
||
|
||
|
||
def test_randomtable_class(): | ||
|
||
""" | ||
Ensure that RandomTable provides a table with the right number of rows and columns. | ||
""" | ||
columns, rows = 4, 60 | ||
table = RandomTable(numflds=columns, numrows=rows) | ||
|
||
assert len(table[0]) == columns | ||
Check notice Code scanning / Semgrep (reported by Codacy) The application was found using assert in non-test code. Note test
The application was found using assert in non-test code.
Check warning Code scanning / Bandit (reported by Codacy) Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Warning test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
|
||
assert len(table) == rows + 1 | ||
Check notice Code scanning / Semgrep (reported by Codacy) The application was found using assert in non-test code. Note test
The application was found using assert in non-test code.
Check warning Code scanning / Bandit (reported by Codacy) Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Warning test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
|
||
|
||
|
||
def test_dummytable_custom_fields(): | ||
|
||
""" | ||
Ensure that dummytable provides a table with the right number of rows | ||
and that it accepts and uses custom column names provided. | ||
""" | ||
columns = ( | ||
('count', partial(pyrandom.randint, 0, 100)), | ||
Check warning Code scanning / Pylintpython3 (reported by Codacy) Module 'random' has no 'randint' member Warning test
Module 'random' has no 'randint' member
Check warning Code scanning / Pylint (reported by Codacy) Module 'random' has no 'randint' member Warning test
Module 'random' has no 'randint' member
|
||
('pet', partial(pyrandom.choice, ['dog', 'cat', 'cow', ])), | ||
Check warning Code scanning / Pylintpython3 (reported by Codacy) Module 'random' has no 'choice' member Warning test
Module 'random' has no 'choice' member
Check warning Code scanning / Pylint (reported by Codacy) Module 'random' has no 'choice' member Warning test
Module 'random' has no 'choice' member
|
||
('color', partial(pyrandom.choice, ['yellow', 'orange', 'brown'])), | ||
Check warning Code scanning / Pylint (reported by Codacy) Module 'random' has no 'choice' member Warning test
Module 'random' has no 'choice' member
Check warning Code scanning / Pylintpython3 (reported by Codacy) Module 'random' has no 'choice' member Warning test
Module 'random' has no 'choice' member
|
||
('value', pyrandom.random), | ||
) | ||
rows = 35 | ||
|
||
table = dummytable(numrows=rows, fields=columns) | ||
assert table[0] == ('count', 'pet', 'color', 'value') | ||
Check warning Code scanning / Bandit (reported by Codacy) Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Warning test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Check notice Code scanning / Semgrep (reported by Codacy) The application was found using assert in non-test code. Note test
The application was found using assert in non-test code.
|
||
assert len(table) == rows + 1 | ||
Check notice Code scanning / Semgrep (reported by Codacy) The application was found using assert in non-test code. Note test
The application was found using assert in non-test code.
Check warning Code scanning / Bandit (reported by Codacy) Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Warning test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
|
||
|
||
|
||
def test_dummytable_no_seed(): | ||
|
||
""" | ||
Ensure that dummytable provides a table with the right number of rows | ||
and columns when not provided with a seed. | ||
""" | ||
rows = 35 | ||
|
||
table = dummytable(numrows=rows) | ||
assert len(table[0]) == 3 | ||
Check notice Code scanning / Semgrep (reported by Codacy) The application was found using assert in non-test code. Note test
The application was found using assert in non-test code.
Check warning Code scanning / Bandit (reported by Codacy) Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Warning test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
|
||
assert len(table) == rows + 1 | ||
Check notice Code scanning / Semgrep (reported by Codacy) The application was found using assert in non-test code. Note test
The application was found using assert in non-test code.
Check warning Code scanning / Bandit (reported by Codacy) Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Warning test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
|
||
|
||
|
||
def test_dummytable_int_seed(): | ||
|
||
""" | ||
Ensure that dummytable provides a table with the right number of rows | ||
and columns when provided with an integer as a seed. | ||
""" | ||
rows = 35 | ||
seed = 42 | ||
table = dummytable(numrows=rows, seed=seed) | ||
assert len(table[0]) == 3 | ||
Check notice Code scanning / Semgrep (reported by Codacy) The application was found using assert in non-test code. Note test
The application was found using assert in non-test code.
Check warning Code scanning / Bandit (reported by Codacy) Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Warning test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
|
||
assert len(table) == rows + 1 | ||
Check notice Code scanning / Semgrep (reported by Codacy) The application was found using assert in non-test code. Note test
The application was found using assert in non-test code.
Check warning Code scanning / Bandit (reported by Codacy) Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Warning test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
|
||
|
||
|
||
def test_dummytable_class(): | ||
|
||
""" | ||
Ensure that DummyTable provides a table with the right number of rows | ||
and columns. | ||
""" | ||
rows = 70 | ||
table = DummyTable(numrows=rows) | ||
|
||
assert len(table) == rows + 1 | ||
Check warning Code scanning / Bandit (reported by Codacy) Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Warning test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Check notice Code scanning / Semgrep (reported by Codacy) The application was found using assert in non-test code. Note test
The application was found using assert in non-test code.
|
Check warning
Code scanning / Pylintpython3 (reported by Codacy)
Missing module docstring Warning test