-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest_twarc_network.py
94 lines (72 loc) · 2.49 KB
/
test_twarc_network.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
import io
import re
import csv
import json
from twarc_network import network
from click.testing import CliRunner
runner = CliRunner()
def test_html():
result = runner.invoke(network, ["test-data/tweets.jsonl"])
assert result.exit_code == 0
m = re.search(r"var graph = ({.*});.*var link = ", result.output, re.DOTALL)
assert m
graph = json.loads(m.group(1))
assert len(graph["nodes"]) == 656
assert len(graph["links"]) == 618
def test_json():
result = runner.invoke(network, ["test-data/tweets.jsonl", "--format", "json"])
assert result.exit_code == 0
graph = json.loads(result.output)
assert len(graph["nodes"]) == 656
assert len(graph["links"]) == 618
def test_gexf():
result = runner.invoke(network, ["test-data/tweets.jsonl", "--format", "gexf"])
assert result.exit_code == 0
def test_gexf():
result = runner.invoke(network, ["test-data/tweets.jsonl", "--format", "gml"])
assert result.exit_code == 0
def test_csv():
result = runner.invoke(network, ["test-data/tweets.jsonl", "--format", "csv"])
assert result.exit_code == 0
data = csv.reader(io.StringIO(result.output))
assert len(list(data)) == 618
def test_min_component():
result = runner.invoke(
network,
["test-data/tweets.jsonl", "--format", "json", "--min-component-size", "4"],
)
graph = json.loads(result.output)
assert len(graph["nodes"]) == 469
def test_max_component():
result = runner.invoke(
network,
["test-data/tweets.jsonl", "--format", "json", "--max-component-size", "15"],
)
graph = json.loads(result.output)
assert len(graph["nodes"]) == 355
def test_tweets():
result = runner.invoke(
network, ["test-data/tweets.jsonl", "--format", "json", "--nodes", "tweets"]
)
assert result.exit_code == 0
graph = json.loads(result.output)
assert len(graph["nodes"]) == 613
def test_hashtags():
result = runner.invoke(
network, ["test-data/tweets.jsonl", "--format", "json", "--nodes", "hashtags"]
)
assert result.exit_code == 0
graph = json.loads(result.output)
assert len(graph["nodes"]) == 352
def test_edges():
result = runner.invoke(
network,
[
"test-data/tweets.jsonl", "--format", "json", "--edges", "retweet",
"--edges", "reply", "--edges", "quote"
]
)
assert result.exit_code == 0
graph = json.loads(result.output)
assert len(graph["nodes"]) == 484
assert len(graph["links"]) == 391