This repository has been archived by the owner on Jan 15, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
memoQProjectTest.py
409 lines (312 loc) · 16.5 KB
/
memoQProjectTest.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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
import unittest
import memoQProject
import json
import os
class MemoQProjectTest(unittest.TestCase):
"""Tests for memoQProject module."""
def __init__(self, *args, **kwargs):
super(MemoQProjectTest, self).__init__(*args, **kwargs)
with open("testFiles/testConfig.json") as json_file:
self.config = json.load(json_file)
def test_get_project_by_domain(self):
""" Test for get_project_by_domain method."""
test = memoQProject.MemoQProject()
test.get_project_by_domain(self.config["valid_domain"])
self.assertNotEqual(test.project.get_project_guid(),
None, "Guid shouldn't be none!")
test.get_project_by_domain(self.config["wrong_domain"])
self.assertEqual(test.project.get_project_guid(),
None, "Guid should be none!")
def test_get_project_by_guid(self):
""" Test for get_project_by_guid method."""
test = memoQProject.MemoQProject()
test.get_project_by_guid(self.config["valid_project_guid"])
self.assertEqual(test.project.get_project_guid(),
self.config["valid_project_guid"], "Guids don't match!")
test.get_project_by_guid(self.config["wrong_project_guid"])
self.assertEqual(test.project.get_project_guid(),
None, "Guid should be none!")
def test_template_project_options(self):
""" Test for template_project_options method."""
test = memoQProject.MemoQProject()
options = test.template_project_options(
self.config["project_template_guid"])
self.assertIsNone(
options, "Options should be None if source language not set!")
test.project.languages.source = self.config["source_language"]
options = test.template_project_options(
self.config["project_template_guid"])
fake_options = test.client.factory.create(
'{http://kilgray.com/memoqservices/2007}TemplateBasedProjectCreateInfo')
fake_options.TemplateGuid = self.config["project_template_guid"]
fake_options.Name = test.project.name
fake_options.SourceLanguageCode = test.project.languages.source
fake_options.Domain = test.project.domain
fake_options.CreatorUser = self.config["creator_guid"]
self.assertEqual(options.Name, fake_options.Name,
"Names should be equal!")
self.assertEqual(options.TemplateGuid, fake_options.TemplateGuid,
"Template guids should be equal!")
self.assertEqual(options.Domain, fake_options.Domain,
"Domains should be equal!")
self.assertEqual(options.SourceLanguageCode, fake_options.SourceLanguageCode,
"Source language codes should be equal!")
def test_create_project_from_template(self):
""" Test for create_project_from_template method."""
test = memoQProject.MemoQProject()
test.project.languages.source = self.config["source_language"]
test.create_project_from_template(
template_guid=self.config["project_template_guid"])
self.assertNotEqual(test.project.get_project_guid(),
None, "Guid shouldn't be none!")
test.delete()
# Testing override
test.project.languages.target = self.config["target_languages"]
options = test.template_project_options(
self.config["project_template_guid"])
options.Name += "_override"
options.Domain = "override"
test.create_project_from_template(options=options)
self.assertNotEqual(test.project.get_project_guid(),
None, "Guid shouldn't be none!")
self.assertEqual(options.Domain, test.project.domain)
self.assertEqual(
self.config["target_languages"], test.project.languages.target)
test.delete()
def test_project_options(self):
""" Test for project_options method."""
test = memoQProject.MemoQProject()
options = test.project_options()
self.assertIsNone(
options, "Options should be None if source language not set!")
test.project.languages.source = self.config["source_language"]
options = test.project_options()
self.assertIsNone(
options, "Options should be None if target languages not set!")
test.project.languages.target = self.config["target_languages"]
options = test.project_options()
fake_options = test.client.factory.create(
'{http://kilgray.com/memoqservices/2007}ServerProjectDesktopDocsCreateInfo')
fake_options.Name = test.project.name
fake_options.SourceLanguageCode = test.project.languages.source
fake_options.TargetLanguageCodes.string = test.project.languages.target
fake_options.Deadline = test.project.deadline
fake_options.RecordVersionHistory = True
fake_options.CreatorUser = self.config["creator_guid"]
self.assertEqual(options.Name, fake_options.Name,
"Names should be equal!")
self.assertEqual(options.TargetLanguageCodes.string, fake_options.TargetLanguageCodes.string,
"Target languages should be equal!")
self.assertEqual(options.Deadline, fake_options.Deadline,
"Deadlines should be equal!")
self.assertEqual(options.SourceLanguageCode, fake_options.SourceLanguageCode,
"Source language codes should be equal!")
self.assertEqual(options.CreatorUser, fake_options.CreatorUser,
"Creators should be equal!")
def test_create_project(self):
""" Test for create_project method."""
test = memoQProject.MemoQProject()
test.project.languages.source = self.config["source_language"]
test.project.languages.target = self.config["target_languages"]
test.create_project()
self.assertNotEqual(test.project.get_project_guid(),
None, "Guid shouldn't be none!")
test.delete()
# Testing override
options = test.project_options()
options.Name += "_override"
options.Domain = "override"
test.create_project(options=options)
self.assertNotEqual(test.project.get_project_guid(),
None, "Guid shouldn't be none!")
self.assertEqual(options.Domain, test.project.domain)
test.delete()
def test_import_document(self):
""" Test for import_document method."""
test = memoQProject.MemoQProject()
test.project.languages.source = self.config["source_language"]
test.project.languages.target = self.config["target_languages"]
test.create_project()
self.assertNotEqual(test.project.get_project_guid(),
None, "Guid shouldn't be none!")
result = test.import_document(self.config["test_file_path"])
self.assertTrue(result, "Result should be true!")
test.delete()
def test_get_project_documents(self):
""" Test for get_project_documents method."""
test = memoQProject.MemoQProject()
test.project.languages.source = self.config["source_language"]
test.project.languages.target = self.config["target_languages"]
test.create_project()
self.assertNotEqual(test.project.get_project_guid(),
None, "Guid shouldn't be none!")
result = test.import_document(self.config["test_file_path"])
self.assertTrue(result, "Result should be true!")
filename = os.path.basename(self.config["test_file_path"])
test.get_project_documents()
self.assertEqual(test.documents[0][0].DocumentName,
filename, "Name of document doesn't match test filename!")
test.delete()
def test_export_documents(self):
""" Test for export_documents method."""
test = memoQProject.MemoQProject()
test.project.languages.source = self.config["source_language"]
test.project.languages.target = self.config["target_languages"]
test.create_project()
self.assertNotEqual(test.project.get_project_guid(),
None, "Guid shouldn't be none!")
result = test.import_document(self.config["test_file_path"])
self.assertTrue(result, "Result should be true!")
filename = os.path.basename(self.config["test_file_path"])
test.get_project_documents()
self.assertEqual(test.documents[0][0].DocumentName,
filename, "Name of document doesn't match test filename!")
export_result = test.export_documents(".")
filepath = os.path.join(".", filename)
self.assertTrue(export_result, "Export result should be true!")
self.assertTrue(os.path.isfile(filepath), "File should exist!")
os.remove(filepath)
test.delete()
def test_export_documents2(self):
""" Test for export_documents2 method."""
test = memoQProject.MemoQProject()
test.project.languages.source = self.config["source_language"]
test.project.languages.target = self.config["target_languages"]
test.create_project()
self.assertNotEqual(test.project.get_project_guid(),
None, "Guid shouldn't be none!")
result = test.import_document(self.config["test_file_path"])
self.assertTrue(result, "Result should be true!")
filename = os.path.basename(self.config["test_file_path"])
test.get_project_documents()
self.assertEqual(test.documents[0][0].DocumentName,
filename, "Name of document doesn't match test filename!")
export_result = test.export_documents2(".")
filepath = os.path.join(".", filename)
self.assertTrue(export_result, "Export result should be true!")
self.assertTrue(os.path.isfile(filepath), "File should exist!")
os.remove(filepath)
test.delete()
def test_statistics_options(self):
""" Test for statistics_options method."""
test = memoQProject.MemoQProject()
fake_options = test.client.factory.create(
'{http://kilgray.com/memoqservices/2007}StatisticsOptions')
fake_options.Analysis_ProjectTMs = True
fake_options.Analysis_Homogenity = True
fake_options.ShowResultsPerFile = True
fake_options.RepetitionPreferenceOver100 = True
statistics_algorithm = test.client.factory.create(
'{http://schemas.datacontract.org/2004/07/MemoQServices}StatisticsAlgorithm')
fake_options.Algorithm.value = statistics_algorithm.MemoQ
options = test.statistics_options()
self.assertEqual(fake_options.Analysis_ProjectTMs, options.Analysis_ProjectTMs,
"Project TMs option shouldn't be different!")
self.assertEqual(fake_options.Analysis_Homogenity, options.Analysis_Homogenity,
"Analysis Homogenity option shouldn't be different!")
self.assertEqual(fake_options.Algorithm.value, options.Algorithm.value,
"Algorithm value shouldn't be different!")
def test_run_statistics(self):
""" Test for run_statistics method."""
test = memoQProject.MemoQProject()
test.project.languages.source = self.config["source_language"]
test.project.languages.target = self.config["target_languages"]
test.create_project()
self.assertNotEqual(test.project.get_project_guid(),
None, "Guid shouldn't be none!")
result = test.import_document(self.config["test_file_path"])
self.assertTrue(result, "Result should be true!")
statistics = test.run_statistics()
self.assertNotEqual(statistics, None, "Statistics shouldn't be none!")
# Testing override
options = test.statistics_options()
options.IncludeLockedRows = True
statistics = test.run_statistics(options=options)
self.assertNotEqual(statistics, None, "Statistics shouldn't be none!")
test.delete()
def test_save_statistics(self):
""" Test for save_statistics method."""
test = memoQProject.MemoQProject()
test.project.languages.source = self.config["source_language"]
test.project.languages.target = self.config["target_languages"]
test.create_project()
self.assertNotEqual(test.project.get_project_guid(),
None, "Guid shouldn't be none!")
result = test.import_document(self.config["test_file_path"])
self.assertTrue(result, "Result should be true!")
test.save_statistics(".", statistics=test.run_statistics())
csv_files = [x for x in os.listdir(
".") if os.path.isfile(x) and ".csv" in x]
self.assertTrue(len(csv_files), "File should exist!")
for csv in csv_files:
os.remove(csv)
# Testing override
options = test.statistics_options()
options.IncludeLockedRows = True
test.save_statistics(".", options=options)
csv_files = [x for x in os.listdir(
".") if os.path.isfile(x) and ".csv" in x]
self.assertTrue(len(csv_files), "File should exist!")
for csv in csv_files:
os.remove(csv)
test.delete()
def test_pretranslate_options(self):
""" Test for pretranslate_options method."""
test = memoQProject.MemoQProject()
fake_options = test.client.factory.create(
'{http://kilgray.com/memoqservices/2007}PretranslateOptions')
lookup_behavior = test.client.factory.create(
'{http://schemas.datacontract.org/2004/07/MemoQServices}PretranslateLookupBehavior')
fake_options.PretranslateLookupBehavior.value = lookup_behavior.GoodMatch
fake_options.GoodMatchRate = 80
fake_options.LockPretranslated = True
options = test.pretranslate_options()
self.assertEqual(
fake_options.PretranslateLookupBehavior.value, options.PretranslateLookupBehavior.value,
"Lookup behavior option shouldn't be different!")
self.assertEqual(fake_options.GoodMatchRate, options.GoodMatchRate,
"Good Match option shouldn't be different!")
self.assertEqual(fake_options.LockPretranslated, options.LockPretranslated,
"Lock Pretranslated options shouldn't be different!")
def test_pretranslate_project(self):
""" Test for pretranslate_project method."""
test = memoQProject.MemoQProject()
test.project.languages.source = self.config["source_language"]
test.create_project_from_template(
template_guid=self.config["project_template_guid"])
self.assertNotEqual(test.project.get_project_guid(),
None, "Guid shouldn't be none!")
result = test.import_document(self.config["test_file_path"])
self.assertTrue(result, "Result should be true!")
self.assertTrue(test.pretranslate_project(),
"Pre-translation shouldn't return false!")
test.delete()
# Testing override
test = memoQProject.MemoQProject()
test.project.languages.source = self.config["source_language"]
test.create_project_from_template(
template_guid=self.config["project_template_guid"])
self.assertNotEqual(test.project.get_project_guid(),
None, "Guid shouldn't be none!")
result = test.import_document(self.config["test_file_path"])
self.assertTrue(result, "Result should be true!")
options = test.pretranslate_options()
options.GoodMatchRate = 90
self.assertTrue(test.pretranslate_project(options=options),
"Pre-translation shouldn't return false!")
test.delete()
def test_delete(self):
""" Test for delete method."""
test = memoQProject.MemoQProject()
test.project.languages.source = self.config["source_language"]
test.project.languages.target = self.config["target_languages"]
test.create_project()
self.assertNotEqual(test.project.get_project_guid(),
None, "Guid shouldn't be none!")
guid = test.project.get_project_guid()
test.delete()
test.get_project_by_guid(guid)
self.assertNotEqual(test.project.get_project_guid(),
guid, "Guids don't match!")
if __name__ == "__main__":
unittest.main()