Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
satella
Manage
Activity
Members
Labels
Plan
Issues
1
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
public
satella
Commits
82dd22ae
Commit
82dd22ae
authored
3 years ago
by
Piotr Maślanka
Browse files
Options
Downloads
Patches
Plain Diff
added random_word
parent
28c502bb
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
CHANGELOG.md
+2
-0
2 additions, 0 deletions
CHANGELOG.md
docs/random.rst
+5
-0
5 additions, 0 deletions
docs/random.rst
satella/__init__.py
+1
-1
1 addition, 1 deletion
satella/__init__.py
satella/random.py
+22
-1
22 additions, 1 deletion
satella/random.py
tests/test_random.py
+8
-1
8 additions, 1 deletion
tests/test_random.py
with
38 additions
and
3 deletions
CHANGELOG.md
+
2
−
0
View file @
82dd22ae
# v2.17.21
# v2.17.21
*
added random_word
This diff is collapsed.
Click to expand it.
docs/random.rst
+
5
−
0
View file @
82dd22ae
...
@@ -11,3 +11,8 @@ random_binary
...
@@ -11,3 +11,8 @@ random_binary
-------------
-------------
.. autofunction:: satella.random.random_binary
.. autofunction:: satella.random.random_binary
random_word
-----------
.. autofunction:: satella.random.random_word
This diff is collapsed.
Click to expand it.
satella/__init__.py
+
1
−
1
View file @
82dd22ae
__version__
=
'
2.17.21a
1
'
__version__
=
'
2.17.21a
2
'
This diff is collapsed.
Click to expand it.
satella/random.py
+
22
−
1
View file @
82dd22ae
import
os
import
os
import
random
import
random
import
typing
as
tp
import
typing
as
tp
import
string
__all__
=
[
'
shuffle_together
'
,
'
random_binary
'
]
__all__
=
[
'
shuffle_together
'
,
'
random_binary
'
,
'
random_word
'
]
from
satella.coding.typing
import
T
def
random_word
(
length
:
int
,
choice
:
T
=
string
.
ascii_lowercase
,
join_fun
:
tp
.
Callable
[[
T
,
...],
T
]
=
lambda
*
args
:
''
.
join
(
args
)):
"""
Build and return a random word of provided length.
The word will be built by calling join_fun with length of arguments picked
at random from choice.
:param length: length of the word
:param choice: a range of characters to use. By default is string.ascii_lowercase
:param join_fun: an argument to be called with randomly picked characters as *args.
Defaults to
''
.join(args), so your T must be a string. If you
'
re passing a
different type, remember to alter this function because the default one expects strings!
:return: a random word
"""
return
join_fun
(
*
(
random
.
choice
(
choice
)
for
_
in
range
(
length
)))
def
random_binary
(
length
:
int
)
->
bytes
:
def
random_binary
(
length
:
int
)
->
bytes
:
...
...
This diff is collapsed.
Click to expand it.
tests/test_random.py
+
8
−
1
View file @
82dd22ae
import
unittest
import
unittest
from
satella.random
import
shuffle_together
,
random_binary
from
satella.random
import
shuffle_together
,
random_binary
,
random_word
import
string
class
TestRandom
(
unittest
.
TestCase
):
class
TestRandom
(
unittest
.
TestCase
):
def
test_random_word
(
self
):
rand_word
=
random_word
(
5
)
self
.
assertEqual
(
len
(
rand_word
),
5
)
self
.
assertTrue
(
all
(
y
in
string
.
ascii_lowercase
for
y
in
rand_word
))
def
test_random_binary
(
self
):
def
test_random_binary
(
self
):
self
.
assertFalse
(
random_binary
(
0
))
self
.
assertFalse
(
random_binary
(
0
))
self
.
assertEqual
(
len
(
random_binary
(
10
)),
10
)
self
.
assertEqual
(
len
(
random_binary
(
10
)),
10
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment