-
Notifications
You must be signed in to change notification settings - Fork 1
/
test_mb.py
129 lines (100 loc) · 2.96 KB
/
test_mb.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
from src.picturecommands_utils import (
as_text,
as_ids,
suggest_audio_video_bitrate,
)
from src.util import (
improve_url,
url_from_s3_key,
get_nonconflicting_filename,
split_text_to_chunks,
)
from src import ctxhelpers
id_text_pairs = [
["1", "1"],
["hi", "hi"],
[203285581004931072, "203285581004931072"],
[3, 3],
[
{"Hello": 203285581004931072},
{"Hello": "203285581004931072"}
],
[None, None]
]
def test_as_text():
for id_val, text_val in id_text_pairs:
assert as_text(id_val) == text_val
def test_as_ids():
for id_val, text_val in id_text_pairs:
assert as_ids(text_val) == id_val
def test_suggest_audio_video_bitrate():
assert suggest_audio_video_bitrate(1) == (64000, 31936000)
assert suggest_audio_video_bitrate(60) == (64000, 469333)
def test_improve_url():
assert improve_url("google.com") == "google.com"
assert improve_url("hi there.com") == "hi+there.com"
def test_url_from_s3_key():
assert url_from_s3_key(
s3_bucket="makumistake",
s3_bucket_location="us-east-2",
s3_key="mykey.txt"
) == "https://makumistake.s3.us-east-2.amazonaws.com/mykey.txt"
def test_get_nonconflicting_filename():
possible_keys = {
"hithere.jpg",
"unknown.png",
"unknown0.png",
"image.png",
"image.jpg",
"image2.png",
"image.jpg.jpg",
}
for possible_key in possible_keys:
new_filename = get_nonconflicting_filename(
possible_key,
existing_keys=possible_keys)
assert new_filename not in possible_keys
class objectview(object):
def __init__(self, d):
self.__dict__ = d
def get_example_ctx():
content_example = objectview({"content": "mb.lupo what's up?"})
ctx_example = {
"prefix": "mb.",
"invoked_with": "lupo",
"message": content_example,
}
return objectview(ctx_example)
def test_get_invocation():
assert ctxhelpers.get_invocation(get_example_ctx()) == "mb.lupo"
def test_get_content_without_invocation():
ctx = get_example_ctx()
assert ctxhelpers.get_content_without_invocation(ctx) == "what's up?"
def test_get_invoked_command():
assert ctxhelpers.get_invoked_command(get_example_ctx()) == "lupo"
def test_split_text_to_chunks():
text = "1 1 1 1234 12345 12 123456 1234 123 1 12 12345678"
assert tuple(split_text_to_chunks(text, block_size=4)) == (
"1 1",
"1",
"1234",
"1234",
"5 12",
"1234",
"56",
"1234",
"123",
"1 12",
"1234",
"5678"
)
def test_split_text_to_chunks_with_max_separator():
text = "1 1 1 1234 12345 12 123456 1234 123 1 12 12345678"
actual_result = tuple(
split_text_to_chunks(text, block_size=20, max_separators=2))
assert actual_result == (
"1 1 1",
"1234 12345 12",
"123456 1234 123",
"1 12 12345678"
)