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 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672
|
#!/usr/bin/env python
from __future__ import print_function
"""
test_job_completion_transform.py
test several cases where the dbdict should be updated
"""
import os
tempdir = os.path.relpath(os.path.abspath(os.path.splitext(__file__)[0])) + "/"
import sys
# add grandparent to search path for testing
grandparent_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", ".."))
sys.path.insert(0, grandparent_dir)
# module name = script name without extension
module_name = os.path.splitext(os.path.basename(__file__))[0]
# funky code to import by file name
parent_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
import ruffus
from ruffus import pipeline_run, pipeline_printout, suffix, transform, split, merge, dbdict, Pipeline
from ruffus.task import get_default_history_file_name
from ruffus.ruffus_utility import RUFFUS_HISTORY_FILE, CHECKSUM_FILE_TIMESTAMPS, CHECKSUM_HISTORY_TIMESTAMPS, CHECKSUM_FUNCTIONS, CHECKSUM_FUNCTIONS_AND_PARAMS
from ruffus.ruffus_exceptions import RethrownJobError
#___________________________________________________________________________
#
# imports
#___________________________________________________________________________
import unittest
import shutil
try:
from StringIO import StringIO
except:
from io import StringIO
import time
import re
possible_chksms = list(range(CHECKSUM_FUNCTIONS_AND_PARAMS + 1))
tempdir = 'tmp_test_job_completion/'
input_file = os.path.join(tempdir, 'input.txt')
transform1_out = input_file.replace('.txt', '.output')
split1_outputs = [ os.path.join(tempdir, 'split.out1.txt'),
os.path.join(tempdir, 'split.out2.txt')]
merge2_output = os.path.join(tempdir, 'merged.out')
runtime_data = []
@transform(input_file, suffix('.txt'), '.output', runtime_data)
def transform1(in_name, out_name, how_many):
with open(out_name, 'w') as outfile:
with open(in_name) as ii:
outfile.write(ii.read())
@transform(input_file, suffix('.txt'), '.output', runtime_data)
def transform_raise_error(in_name, out_name, how_many):
# raise an error unless runtime_data has 'okay' in it
with open(out_name, 'w') as outfile:
with open(in_name) as ii:
outfile.write(ii.read())
if 'okay' not in how_many:
raise RuntimeError("'okay' wasn't in runtime_data!")
@split(input_file, split1_outputs)
def split1(in_name, out_names):
for n in out_names:
with open(n, 'w') as outfile:
with open(in_name) as ii:
outfile.write(ii.read() + '\n')
@merge(split1, merge2_output)
def merge2(in_names, out_name):
with open(out_name, 'w') as outfile:
for n in in_names:
with open(n) as ii:
outfile.write(ii.read() + '\n')
#CHECKSUM_FILE_TIMESTAMPS = 0 # only rerun when the file timestamps are out of date (classic mode)
#CHECKSUM_HISTORY_TIMESTAMPS = 1 # also rerun when the history shows a job as being out of date
#CHECKSUM_FUNCTIONS = 2 # also rerun when function body has changed
#CHECKSUM_FUNCTIONS_AND_PARAMS = 3 # also rerun when function parameters have changed
def cleanup_tmpdir():
os.system('rm -f %s %s' % (os.path.join(tempdir, '*'), get_default_history_file_name()))
count_pipelines = 0
class TestJobCompletion(unittest.TestCase):
def setUp(self):
try:
os.mkdir(tempdir)
except OSError:
pass
def create_pipeline (self):
"""
Create new pipeline on the fly without using decorators
"""
global count_pipelines
count_pipelines = count_pipelines + 1
test_pipeline = Pipeline("test %d" % count_pipelines)
test_pipeline.transform(task_func = transform1,
input = input_file,
filter = suffix('.txt'),
output = '.output',
extras = [runtime_data])
test_pipeline.transform(task_func = transform_raise_error,
input = input_file,
filter = suffix('.txt'),
output = '.output',
extras = [runtime_data])
test_pipeline.split( task_func = split1,
input = input_file,
output = split1_outputs)
test_pipeline.merge( task_func = merge2,
input = split1,
output = merge2_output)
return test_pipeline
def test_output_doesnt_exist(self):
"""Input file exists, output doesn't exist"""
# output doesn't exist-- should run for all levels
# create a new input file
cleanup_tmpdir()
with open(input_file, 'w') as outfile:
outfile.write('testme')
for chksm in possible_chksms:
s = StringIO()
pipeline_printout(s, [transform1], verbose=6, checksum_level=chksm, pipeline= "main")
self.assertTrue(re.search(r'Job needs update:.*Missing file.*\[tmp_test_job_completion/input.output\]'
, s.getvalue(), re.DOTALL))
def test_output_out_of_date(self):
"""Input file exists, output out of date"""
# output exists but is out of date-- should run for all levels
cleanup_tmpdir()
with open(transform1_out, 'w') as outfile:
outfile.write('testme')
time.sleep(0.1)
with open(input_file, 'w') as outfile:
outfile.write('testme')
for chksm in possible_chksms:
s = StringIO()
pipeline_printout(s, [transform1], verbose=6, checksum_level=chksm, pipeline= "main")
self.assertIn('Job needs update:', s.getvalue())
if chksm == CHECKSUM_FILE_TIMESTAMPS:
self.assertIn('Input files:', s.getvalue())
self.assertIn('Output files:', s.getvalue())
else:
self.assertIn('left over from a failed run?', s.getvalue())
def test_output_timestamp_okay(self):
"""Input file exists, output timestamp up to date"""
# output exists and timestamp is up to date-- not run for lvl 0, run for all others
cleanup_tmpdir()
with open(input_file, 'w') as outfile:
outfile.write('testme')
time.sleep(0.1)
with open(transform1_out, 'w') as outfile:
outfile.write('testme')
for chksm in possible_chksms:
s = StringIO()
pipeline_printout(s, [transform1], verbose=6, checksum_level=chksm, pipeline= "main")
if chksm == CHECKSUM_FILE_TIMESTAMPS:
#self.assertIn('Job up-to-date', s.getvalue())
pass
else:
self.assertIn('Job needs update:', s.getvalue())
self.assertIn('left over from a failed run?',
s.getvalue())
def test_output_up_to_date(self):
"""Input file exists, output up to date"""
# output is up to date-- not run for any levels
cleanup_tmpdir()
with open(input_file, 'w') as outfile:
outfile.write('testme')
pipeline_run([transform1], verbose=0, checksum_level=CHECKSUM_HISTORY_TIMESTAMPS, pipeline= "main")
for chksm in possible_chksms:
s = StringIO()
pipeline_printout(s, [transform1], verbose=6, checksum_level=chksm, pipeline= "main")
#self.assertIn('Job up-to-date', s.getvalue())
pass
def test_output_up_to_date_func_changed(self):
"""Input file exists, output up to date, function body changed"""
# output is up to date, but function body changed (e.g., source different)
cleanup_tmpdir()
with open(input_file, 'w') as outfile:
outfile.write('testme')
pipeline_run([transform1], verbose=0, checksum_level=CHECKSUM_HISTORY_TIMESTAMPS, pipeline= "main")
if sys.hexversion >= 0x03000000:
transform1.__code__ = split1.__code__ # simulate source change
else:
transform1.func_code = split1.func_code # simulate source change
for chksm in possible_chksms:
s = StringIO()
pipeline_printout(s, [transform1], verbose=6, checksum_level=chksm, pipeline= "main")
if chksm >= CHECKSUM_FUNCTIONS:
self.assertIn('Job needs update:', s.getvalue())
self.assertIn('Pipeline function has changed',
s.getvalue())
else:
#self.assertIn('Job up-to-date', s.getvalue())
pass
def test_output_up_to_date_func_changed(self):
"""Input file exists, output up to date, function body changed"""
# output is up to date, but function body changed (e.g., source different)
cleanup_tmpdir()
with open(input_file, 'w') as outfile:
outfile.write('testme')
pipeline_run([transform1], verbose=0, checksum_level=CHECKSUM_HISTORY_TIMESTAMPS, pipeline= "main")
# simulate source change
if sys.hexversion >= 0x03000000:
split1.__code__, transform1.__code__ = transform1.__code__, split1.__code__
else:
split1.func_code, transform1.func_code = transform1.func_code, split1.func_code
for chksm in possible_chksms:
s = StringIO()
pipeline_printout(s, [transform1], verbose=6, checksum_level=chksm, pipeline= "main")
if chksm >= CHECKSUM_FUNCTIONS:
self.assertIn('Job needs update:', s.getvalue())
self.assertIn('Pipeline function has changed',
s.getvalue())
else:
#self.assertIn('Job up-to-date', s.getvalue())
pass
# clean up our function-changing mess!
if sys.hexversion >= 0x03000000:
split1.__code__, transform1.__code__ = transform1.__code__, split1.__code__
else:
split1.func_code, transform1.func_code = transform1.func_code, split1.func_code
def test_output_up_to_date_param_changed(self):
"""Input file exists, output up to date, parameter to function changed"""
# output is up to date, but function body changed (e.g., source different)
cleanup_tmpdir()
with open(input_file, 'w') as outfile:
outfile.write('testme')
pipeline_run([transform1], verbose=0, checksum_level=CHECKSUM_HISTORY_TIMESTAMPS, pipeline= "main")
runtime_data.append('different') # simulate change to config file
for chksm in possible_chksms:
s = StringIO()
pipeline_printout(s, [transform1], verbose=6, checksum_level=chksm, pipeline= "main")
if chksm >= CHECKSUM_FUNCTIONS_AND_PARAMS:
self.assertIn('Job needs update:', s.getvalue())
self.assertIn('Pipeline parameters have changed',
s.getvalue())
else:
#self.assertIn('Job up-to-date', s.getvalue())
pass
def test_split_output(self):
"""test multiple-output checksums"""
# outputs out of date
cleanup_tmpdir()
with open(input_file, 'w') as outfile:
outfile.write('testme')
pipeline_run([split1], verbose=0, checksum_level=CHECKSUM_HISTORY_TIMESTAMPS, pipeline= "main")
time.sleep(.5)
with open(input_file, 'w') as outfile:
outfile.write('testme')
for chksm in possible_chksms:
s = StringIO()
pipeline_printout(s, [split1], verbose=6, checksum_level=chksm, pipeline= "main")
self.assertIn('Job needs update:', s.getvalue())
# all outputs incorrectly generated
cleanup_tmpdir()
with open(input_file, 'w') as outfile:
outfile.write('testme')
time.sleep(.5)
for f in split1_outputs:
with open(f, 'w') as outfile:
outfile.write('testme')
for chksm in possible_chksms:
s = StringIO()
pipeline_printout(s, [split1], verbose=6, checksum_level=chksm, pipeline= "main")
if chksm >= CHECKSUM_HISTORY_TIMESTAMPS:
self.assertIn('Job needs update:', s.getvalue())
self.assertIn('left over from a failed run?',
s.getvalue())
else:
#self.assertIn('Job up-to-date', s.getvalue())
pass
# one output incorrectly generated
cleanup_tmpdir()
with open(input_file, 'w') as outfile:
outfile.write('testme')
pipeline_run([split1], verbose=0, checksum_level=CHECKSUM_HISTORY_TIMESTAMPS, pipeline= "main")
job_history = dbdict.open(get_default_history_file_name(), picklevalues=True)
del job_history[os.path.relpath(split1_outputs[0])]
for chksm in possible_chksms:
s = StringIO()
pipeline_printout(s, [split1], verbose=6, checksum_level=chksm, pipeline= "main")
if chksm >= CHECKSUM_HISTORY_TIMESTAMPS:
self.assertIn('Job needs update:', s.getvalue())
self.assertIn('left over from a failed run?',
s.getvalue())
else:
#self.assertIn('Job up-to-date', s.getvalue())
pass
def test_merge_output(self):
"""test multiple-input checksums"""
# one output incorrectly generated
cleanup_tmpdir()
with open(input_file, 'w') as outfile:
outfile.write('testme')
pipeline_run([split1], verbose=0, checksum_level=CHECKSUM_HISTORY_TIMESTAMPS, pipeline= "main")
job_history = dbdict.open(get_default_history_file_name(), picklevalues=True)
del job_history[os.path.relpath(split1_outputs[0])]
for chksm in possible_chksms:
s = StringIO()
pipeline_printout(s, [merge2], verbose=6, checksum_level=chksm, pipeline= "main")
if chksm >= CHECKSUM_HISTORY_TIMESTAMPS:
self.assertIn('Job needs update:', s.getvalue())
self.assertIn('left over from a failed run?', s.getvalue())
else:
#self.assertIn('Job up-to-date', s.getvalue())
pass
# make sure the jobs run fine
cleanup_tmpdir()
with open(input_file, 'w') as outfile:
outfile.write('testme')
pipeline_run([merge2], verbose=0, checksum_level=CHECKSUM_HISTORY_TIMESTAMPS, pipeline= "main")
for chksm in possible_chksms:
s = StringIO()
pipeline_printout(s, [merge2], verbose=6, checksum_level=chksm, pipeline= "main")
#self.assertIn('Job up-to-date', s.getvalue())
self.assertNotIn('Job needs update:', s.getvalue())
self.assertNotIn('left over from a failed run?', s.getvalue())
def test_newstyle_output_doesnt_exist(self):
"""Input file exists, output doesn't exist"""
# output doesn't exist-- should run for all levels
# create a new input file
cleanup_tmpdir()
with open(input_file, 'w') as outfile:
outfile.write('testme')
for chksm in possible_chksms:
s = StringIO()
self.create_pipeline().printout(s, [transform1], verbose=6, checksum_level=chksm)
self.assertTrue(re.search(r'Job needs update:.*Missing file.*\[tmp_test_job_completion/input.output\]'
, s.getvalue(), re.DOTALL))
def test_newstyle_output_out_of_date(self):
"""Input file exists, output out of date"""
# output exists but is out of date-- should run for all levels
cleanup_tmpdir()
with open(transform1_out, 'w') as outfile:
outfile.write('testme')
time.sleep(0.1)
with open(input_file, 'w') as outfile:
outfile.write('testme')
for chksm in possible_chksms:
s = StringIO()
self.create_pipeline().printout(s, [transform1], verbose=6, checksum_level=chksm)
self.assertIn('Job needs update:', s.getvalue())
if chksm == CHECKSUM_FILE_TIMESTAMPS:
self.assertIn('Input files:', s.getvalue())
self.assertIn('Output files:', s.getvalue())
else:
self.assertIn('left over from a failed run?', s.getvalue())
def test_newstyle_output_timestamp_okay(self):
"""Input file exists, output timestamp up to date"""
# output exists and timestamp is up to date-- not run for lvl 0, run for all others
cleanup_tmpdir()
with open(input_file, 'w') as outfile:
outfile.write('testme')
time.sleep(0.1)
with open(transform1_out, 'w') as outfile:
outfile.write('testme')
for chksm in possible_chksms:
s = StringIO()
self.create_pipeline().printout(s, [transform1], verbose=6, checksum_level=chksm)
if chksm == CHECKSUM_FILE_TIMESTAMPS:
#self.assertIn('Job up-to-date', s.getvalue())
pass
else:
self.assertIn('Job needs update:', s.getvalue())
self.assertIn('left over from a failed run?',
s.getvalue())
def test_newstyle_output_up_to_date(self):
"""Input file exists, output up to date"""
test_pipeline = self.create_pipeline()
# output is up to date-- not run for any levels
cleanup_tmpdir()
with open(input_file, 'w') as outfile:
outfile.write('testme')
test_pipeline.run([transform1], verbose=0, checksum_level=CHECKSUM_HISTORY_TIMESTAMPS)
for chksm in possible_chksms:
s = StringIO()
test_pipeline.printout(s, [transform1], verbose=6, checksum_level=chksm)
#self.assertIn('Job up-to-date', s.getvalue())
pass
def test_newstyle_output_up_to_date_func_changed(self):
"""Input file exists, output up to date, function body changed"""
test_pipeline = self.create_pipeline()
# output is up to date, but function body changed (e.g., source different)
cleanup_tmpdir()
with open(input_file, 'w') as outfile:
outfile.write('testme')
test_pipeline.run([transform1], verbose=0, checksum_level=CHECKSUM_HISTORY_TIMESTAMPS)
if sys.hexversion >= 0x03000000:
transform1.__code__ = split1.__code__ # simulate source change
else:
transform1.func_code = split1.func_code # simulate source change
for chksm in possible_chksms:
s = StringIO()
test_pipeline.printout(s, [transform1], verbose=6, checksum_level=chksm)
if chksm >= CHECKSUM_FUNCTIONS:
self.assertIn('Job needs update:', s.getvalue())
self.assertIn('Pipeline function has changed',
s.getvalue())
else:
#self.assertIn('Job up-to-date', s.getvalue())
pass
def test_newstyle_output_up_to_date_func_changed(self):
"""Input file exists, output up to date, function body changed"""
test_pipeline = self.create_pipeline()
# output is up to date, but function body changed (e.g., source different)
cleanup_tmpdir()
with open(input_file, 'w') as outfile:
outfile.write('testme')
test_pipeline.run([transform1], verbose=0, checksum_level=CHECKSUM_HISTORY_TIMESTAMPS)
# simulate source change
if sys.hexversion >= 0x03000000:
split1.__code__, transform1.__code__ = transform1.__code__, split1.__code__
else:
split1.func_code, transform1.func_code = transform1.func_code, split1.func_code
for chksm in possible_chksms:
s = StringIO()
test_pipeline.printout(s, [transform1], verbose=6, checksum_level=chksm)
if chksm >= CHECKSUM_FUNCTIONS:
self.assertIn('Job needs update:', s.getvalue())
self.assertIn('Pipeline function has changed',
s.getvalue())
else:
#self.assertIn('Job up-to-date', s.getvalue())
pass
# clean up our function-changing mess!
if sys.hexversion >= 0x03000000:
split1.__code__, transform1.__code__ = transform1.__code__, split1.__code__
else:
split1.func_code, transform1.func_code = transform1.func_code, split1.func_code
def test_newstyle_output_up_to_date_param_changed(self):
"""Input file exists, output up to date, parameter to function changed"""
test_pipeline = self.create_pipeline()
# output is up to date, but function body changed (e.g., source different)
cleanup_tmpdir()
with open(input_file, 'w') as outfile:
outfile.write('testme')
test_pipeline.run([transform1], verbose=0, checksum_level=CHECKSUM_HISTORY_TIMESTAMPS)
runtime_data.append('different') # simulate change to config file
for chksm in possible_chksms:
s = StringIO()
test_pipeline.printout(s, [transform1], verbose=6, checksum_level=chksm)
if chksm >= CHECKSUM_FUNCTIONS_AND_PARAMS:
self.assertIn('Job needs update:', s.getvalue())
self.assertIn('Pipeline parameters have changed',
s.getvalue())
else:
#self.assertIn('Job up-to-date', s.getvalue())
pass
def test_raises_error(self):
"""run a function that fails but creates output, then check what should run"""
# output is up to date, but function body changed (e.g., source different)
cleanup_tmpdir()
with open(input_file, 'w') as outfile:
outfile.write('testme')
time.sleep(.5)
del runtime_data[:]
with self.assertRaises(RethrownJobError): # poo. Shouldn't this be RuntimeError?
pipeline_run([transform_raise_error], verbose=0, checksum_level=CHECKSUM_HISTORY_TIMESTAMPS, pipeline= "main") # generates output then fails
for chksm in possible_chksms:
s = StringIO()
pipeline_printout(s, [transform_raise_error], verbose=6, checksum_level=chksm, pipeline= "main")
if chksm >= CHECKSUM_HISTORY_TIMESTAMPS:
self.assertIn('Job needs update:', s.getvalue())
self.assertIn('left over from a failed run?',
s.getvalue())
else:
#self.assertIn('Job up-to-date', s.getvalue())
pass
def test_newstyle_raises_error(self):
"""run a function that fails but creates output, then check what should run"""
test_pipeline = self.create_pipeline()
# output is up to date, but function body changed (e.g., source different)
cleanup_tmpdir()
with open(input_file, 'w') as outfile:
outfile.write('testme')
time.sleep(.5)
del runtime_data[:]
with self.assertRaises(RethrownJobError): # poo. Shouldn't this be RuntimeError?
test_pipeline.run([transform_raise_error], verbose=0, checksum_level=CHECKSUM_HISTORY_TIMESTAMPS) # generates output then fails
for chksm in possible_chksms:
s = StringIO()
test_pipeline.printout(s, [transform_raise_error], verbose=6, checksum_level=chksm)
if chksm >= CHECKSUM_HISTORY_TIMESTAMPS:
self.assertIn('Job needs update:', s.getvalue())
self.assertIn('left over from a failed run?',
s.getvalue())
else:
#self.assertIn('Job up-to-date', s.getvalue())
pass
def test_newstyle_split_output(self):
"""test multiple-output checksums"""
test_pipeline = self.create_pipeline()
# outputs out of date
cleanup_tmpdir()
with open(input_file, 'w') as outfile:
outfile.write('testme')
test_pipeline.run([split1], verbose=0, checksum_level=CHECKSUM_HISTORY_TIMESTAMPS)
time.sleep(.5)
with open(input_file, 'w') as outfile:
outfile.write('testme')
for chksm in possible_chksms:
s = StringIO()
test_pipeline.printout(s, [split1], verbose=6, checksum_level=chksm)
self.assertIn('Job needs update:', s.getvalue())
# all outputs incorrectly generated
cleanup_tmpdir()
with open(input_file, 'w') as outfile:
outfile.write('testme')
time.sleep(.5)
for f in split1_outputs:
with open(f, 'w') as outfile:
outfile.write('testme')
for chksm in possible_chksms:
s = StringIO()
test_pipeline.printout(s, [split1], verbose=6, checksum_level=chksm)
if chksm >= CHECKSUM_HISTORY_TIMESTAMPS:
self.assertIn('Job needs update:', s.getvalue())
self.assertIn('left over from a failed run?',
s.getvalue())
else:
#self.assertIn('Job up-to-date', s.getvalue())
pass
# one output incorrectly generated
cleanup_tmpdir()
with open(input_file, 'w') as outfile:
outfile.write('testme')
test_pipeline.run([split1], verbose=0, checksum_level=CHECKSUM_HISTORY_TIMESTAMPS)
job_history = dbdict.open(get_default_history_file_name(), picklevalues=True)
del job_history[os.path.relpath(split1_outputs[0])]
for chksm in possible_chksms:
s = StringIO()
test_pipeline.printout(s, [split1], verbose=6, checksum_level=chksm)
if chksm >= CHECKSUM_HISTORY_TIMESTAMPS:
self.assertIn('Job needs update:', s.getvalue())
self.assertIn('left over from a failed run?',
s.getvalue())
else:
#self.assertIn('Job up-to-date', s.getvalue())
pass
def test_newstyle_merge_output(self):
"""test multiple-input checksums"""
test_pipeline = self.create_pipeline()
# one output incorrectly generated
cleanup_tmpdir()
with open(input_file, 'w') as outfile:
outfile.write('testme')
test_pipeline.run([split1], verbose=0, checksum_level=CHECKSUM_HISTORY_TIMESTAMPS)
job_history = dbdict.open(get_default_history_file_name(), picklevalues=True)
del job_history[os.path.relpath(split1_outputs[0])]
for chksm in possible_chksms:
s = StringIO()
test_pipeline.printout(s, [merge2], verbose=6, checksum_level=chksm)
if chksm >= CHECKSUM_HISTORY_TIMESTAMPS:
self.assertIn('Job needs update:', s.getvalue())
self.assertIn('left over from a failed run?', s.getvalue())
else:
#self.assertIn('Job up-to-date', s.getvalue())
pass
# make sure the jobs run fine
cleanup_tmpdir()
with open(input_file, 'w') as outfile:
outfile.write('testme')
test_pipeline.run([merge2], verbose=0, checksum_level=CHECKSUM_HISTORY_TIMESTAMPS)
for chksm in possible_chksms:
s = StringIO()
test_pipeline.printout(s, [merge2], verbose=6, checksum_level=chksm)
#self.assertIn('Job up-to-date', s.getvalue())
self.assertNotIn('Job needs update:', s.getvalue())
self.assertNotIn('left over from a failed run?', s.getvalue())
def tearDown(self):
shutil.rmtree(tempdir)
pass
if __name__ == '__main__':
unittest.main()
# try:
# os.mkdir(tempdir)
# except OSError:
# pass
# #os.system('rm %s/*' % tempdir)
# #open(input_file, 'w').close()
# s = StringIO()
# pipeline_run([transform1], checksum_level=CHECKSUM_HISTORY_TIMESTAMPS, pipeline= "main")
# pipeline_printout(s, [transform1], verbose=6, checksum_level=0, pipeline= "main")
# print s.getvalue()
# #open(transform1_out) # raise an exception if test fails
|