1 from translate.search import match
2 from translate.storage import csvl10n
3
5 """Test the matching class"""
7 """returns only the candidate strings out of the list with (score, string) tuples"""
8 return [unit.source for unit in units]
9
10 - def buildcsv(self, sources, targets=None):
21
23 """Test basic matching"""
24 csvfile = self.buildcsv(["hand", "asdf", "fdas", "haas", "pond"])
25 matcher = match.matcher(csvfile)
26 candidates = self.candidatestrings(matcher.matches("hond"))
27 candidates.sort()
28 assert candidates == ["hand", "pond"]
29 message = "Ek skop die bal"
30 csvfile = self.buildcsv(
31 ["Hy skop die bal",
32 message,
33 "Jannie skop die bal",
34 "Ek skop die balle",
35 "Niemand skop die bal nie"])
36 matcher = match.matcher(csvfile)
37 candidates = self.candidatestrings(matcher.matches(message))
38 assert len(candidates) == 3
39
40 assert candidates[0] == message
41 candidates.sort()
42 assert candidates[1:] == ["Ek skop die balle", "Hy skop die bal"]
43
45 """Test using multiple datastores"""
46 csvfile1 = self.buildcsv(["hand", "asdf", "fdas"])
47 csvfile2 = self.buildcsv(["haas", "pond"])
48 matcher = match.matcher([csvfile1, csvfile2])
49 candidates = self.candidatestrings(matcher.matches("hond"))
50 candidates.sort()
51 assert candidates == ["hand", "pond"]
52 message = "Ek skop die bal"
53 csvfile1 = self.buildcsv(
54 ["Hy skop die bal",
55 message,
56 "Jannie skop die bal"])
57 csvfile2 = self.buildcsv(
58 ["Ek skop die balle",
59 "Niemand skop die bal nie"])
60 matcher = match.matcher([csvfile1, csvfile2])
61 candidates = self.candidatestrings(matcher.matches(message))
62 assert len(candidates) == 3
63
64 assert candidates[0] == message
65 candidates.sort()
66 assert candidates[1:] == ["Ek skop die balle", "Hy skop die bal"]
67
80
87