|
1
|
|
|
""" Unit testing module for pre-processing functions """ |
|
2
|
|
|
|
|
3
|
|
|
import unittest |
|
4
|
|
|
import string |
|
5
|
|
|
|
|
6
|
|
|
import crowdtruth |
|
7
|
|
|
from crowdtruth.configuration import DefaultConfig |
|
8
|
|
|
|
|
9
|
|
|
TEST_FILE_PREF = "test/test_data/load/" |
|
10
|
|
|
|
|
11
|
|
|
class TestConfig(DefaultConfig): |
|
12
|
|
|
inputColumns = ["input"] |
|
13
|
|
|
outputColumns = ["Answer.output"] |
|
14
|
|
|
open_ended_task = False |
|
15
|
|
|
annotation_separator = " " |
|
16
|
|
|
annotation_vector = list(string.ascii_uppercase) |
|
17
|
|
|
def processJudgments(self, judgments): |
|
18
|
|
|
return judgments |
|
19
|
|
|
|
|
20
|
|
|
class TestLoad(unittest.TestCase): |
|
21
|
|
|
test_conf_const = TestConfig() |
|
22
|
|
|
|
|
23
|
|
|
def test_platform(self): |
|
24
|
|
|
for w in range(1, 6): |
|
25
|
|
|
test_config_amt = self.test_conf_const.__class__ |
|
26
|
|
|
data_amt, _ = crowdtruth.load( |
|
27
|
|
|
file=TEST_FILE_PREF + "platform_amt" + str(w) + ".csv", |
|
28
|
|
|
config=test_config_amt()) |
|
29
|
|
|
test_config_cf = self.test_conf_const.__class__ |
|
30
|
|
|
data_cf, _ = crowdtruth.load( |
|
31
|
|
|
file=TEST_FILE_PREF + "platform_cf" + str(w) + ".csv", |
|
32
|
|
|
config=test_config_cf()) |
|
33
|
|
|
self.assertEqual( |
|
34
|
|
|
(set(data_cf["units"]["duration"].keys()) - |
|
35
|
|
|
set(data_amt["units"]["duration"].keys())), |
|
36
|
|
|
set([])) |
|
37
|
|
|
self.assertEqual( |
|
38
|
|
|
(set(data_cf["workers"]["judgment"].keys()) - |
|
39
|
|
|
set(data_amt["workers"]["judgment"].keys())), |
|
40
|
|
|
set([])) |
|
41
|
|
|
self.assertEqual( |
|
42
|
|
|
set(data_cf["workers"]["judgment"] - data_amt["workers"]["judgment"]), |
|
43
|
|
|
set([0])) |
|
44
|
|
|
|
|
45
|
|
|
def test_folder(self): |
|
46
|
|
|
test_config = self.test_conf_const.__class__ |
|
47
|
|
|
data, _ = crowdtruth.load( |
|
48
|
|
|
directory=TEST_FILE_PREF + "dir/", |
|
49
|
|
|
config=test_config()) |
|
50
|
|
|
self.assertEqual(data["workers"].shape[0], 7) |
|
51
|
|
|
self.assertEqual(data["units"].shape[0], 2) |
|
52
|
|
|
self.assertEqual(data["judgments"].shape[0], 12) |
|
53
|
|
|
|