Class: Syskit::GUI::Testing::SubprocessItem

Inherits:
Qt::StandardItem
  • Object
show all
Defined in:
lib/syskit/gui/testing.rb

Defined Under Namespace

Classes: TestResult

Constant Summary collapse

SLAVE_OBJECT_ID_ROLE =
Qt::UserRole + 1
SLAVE_PID_ROLE =
Qt::UserRole + 2
COLORS =
Hash[
blue: Qt::Color.new(51, 181, 229),
green: Qt::Color.new(153, 204, 0),
grey: Qt::Color.new(128, 128, 128),
red: Qt::Color.new(255, 68, 68),
orange: Qt::Color.new(255, 209, 101)]
NEW_SLAVE_BACKGROUND =
COLORS[:blue]
SKIP_BACKGROUND =
COLORS[:orange]
RUNNING_BACKGROUND =
COLORS[:green]
SUCCESS_BACKGROUND =
COLORS[:grey]
FAILED_BACKGROUND =
COLORS[:red]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app, slave) ⇒ SubprocessItem

Returns a new instance of SubprocessItem



361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
# File 'lib/syskit/gui/testing.rb', line 361

def initialize(app, slave)
    super()

    clear

    @has_tested = false
    @executed = false
    @slave = slave
    @total_run_count = 0
    name = (slave.name[:path] || "Robot: #{app.robot_name}")
    if base_path = app.find_base_path_for(name)
        base_path = base_path.to_s
        name = File.basename(base_path) + ":" + name[(base_path.size + 1)..-1]
    end
    @name = name

    self.text = name
    self.background = Qt::Brush.new(Qt::Color.new(NEW_SLAVE_BACKGROUND))
end

Instance Attribute Details

#assertions_countObject (readonly)

Returns the value of attribute assertions_count



350
351
352
# File 'lib/syskit/gui/testing.rb', line 350

def assertions_count
  @assertions_count
end

#exceptionsObject (readonly)

Returns the value of attribute exceptions



347
348
349
# File 'lib/syskit/gui/testing.rb', line 347

def exceptions
  @exceptions
end

#failure_countObject (readonly)

Returns the value of attribute failure_count



351
352
353
# File 'lib/syskit/gui/testing.rb', line 351

def failure_count
  @failure_count
end

#nameObject (readonly)

Returns the value of attribute name



345
346
347
# File 'lib/syskit/gui/testing.rb', line 345

def name
  @name
end

#skip_countObject (readonly)

Returns the value of attribute skip_count



352
353
354
# File 'lib/syskit/gui/testing.rb', line 352

def skip_count
  @skip_count
end

#slaveObject (readonly)

Returns the value of attribute slave



344
345
346
# File 'lib/syskit/gui/testing.rb', line 344

def slave
  @slave
end

#slave_exit_statusObject (readonly)

Returns the value of attribute slave_exit_status



354
355
356
# File 'lib/syskit/gui/testing.rb', line 354

def slave_exit_status
  @slave_exit_status
end

#start_timeObject (readonly)

Returns the value of attribute start_time



349
350
351
# File 'lib/syskit/gui/testing.rb', line 349

def start_time
  @start_time
end

#test_resultsObject (readonly)

Returns the value of attribute test_results



346
347
348
# File 'lib/syskit/gui/testing.rb', line 346

def test_results
  @test_results
end

#total_run_countObject (readonly)

Returns the value of attribute total_run_count



356
357
358
# File 'lib/syskit/gui/testing.rb', line 356

def total_run_count
  @total_run_count
end

Class Method Details

.html_color(name) ⇒ Object



331
332
333
334
# File 'lib/syskit/gui/testing.rb', line 331

def self.html_color(name)
    color = COLORS[name]
    "rgb(%i,%i,%i)" % [color.red, color.green, color.blue]
end

Instance Method Details

#add_exception(e) ⇒ Object



512
513
514
515
# File 'lib/syskit/gui/testing.rb', line 512

def add_exception(e)
    exceptions << e
    update_text
end

#add_test_result(file, test_case_name, test_name, failures, assertions, time) ⇒ Object



497
498
499
500
501
502
503
504
505
506
507
508
509
510
# File 'lib/syskit/gui/testing.rb', line 497

def add_test_result(file, test_case_name, test_name, failures, assertions, time)
    skip_count, failure_count = 0, 0
    failures.each do |e|
        if e.kind_of?(Minitest::Skip)
            skip_count += 1
        else failure_count += 1
        end
    end
    @skip_count += skip_count
    @failure_count += failure_count
    @assertions_count += assertions
    test_results << TestResult.new(file, test_case_name, test_name, skip_count, failure_count, failures, assertions, time)
    update_text
end

#clearObject



517
518
519
520
521
522
523
# File 'lib/syskit/gui/testing.rb', line 517

def clear
    @failure_count = 0
    @skip_count = 0
    @assertions_count = 0
    @test_results = Array.new
    @exceptions = Array.new
end

#discovery_finishedObject



466
467
# File 'lib/syskit/gui/testing.rb', line 466

def discovery_finished
end

#discovery_startObject



463
464
# File 'lib/syskit/gui/testing.rb', line 463

def discovery_start
end

#each_test_result(&block) ⇒ Object



381
382
383
# File 'lib/syskit/gui/testing.rb', line 381

def each_test_result(&block)
    test_results.each(&block)
end

#exception_countObject

The count of exceptions



359
# File 'lib/syskit/gui/testing.rb', line 359

def exception_count; exceptions.size end

#executed?Boolean

Returns:

  • (Boolean)


401
402
403
# File 'lib/syskit/gui/testing.rb', line 401

def executed?
    @executed
end

#finished(slave_exit_status) ⇒ Object



428
429
430
431
432
433
434
435
436
437
438
439
440
441
# File 'lib/syskit/gui/testing.rb', line 428

def finished(slave_exit_status)
    @slave_exit_status = slave_exit_status
    @runtime = runtime
    if has_failures? || has_exceptions? || slave_failed?
        self.background = Qt::Brush.new(Qt::Color.new(FAILED_BACKGROUND))
    elsif has_skips?
        self.background = Qt::Brush.new(Qt::Color.new(SKIP_BACKGROUND))
    elsif has_tested?
        self.background = Qt::Brush.new(Qt::Color.new(SUCCESS_BACKGROUND))
    else
        self.background = Qt::Brush.new(Qt::Color.new(NEW_SLAVE_BACKGROUND))
    end
    update_text
end

#finished?Boolean

Returns:

  • (Boolean)


405
406
407
# File 'lib/syskit/gui/testing.rb', line 405

def finished?
    !!@runtime
end

#has_exceptions?Boolean

Returns:

  • (Boolean)


489
490
491
# File 'lib/syskit/gui/testing.rb', line 489

def has_exceptions?
    !exceptions.empty?
end

#has_failures?Boolean

Returns:

  • (Boolean)


485
486
487
# File 'lib/syskit/gui/testing.rb', line 485

def has_failures?
    failure_count > 0
end

#has_skips?Boolean

Returns:

  • (Boolean)


481
482
483
# File 'lib/syskit/gui/testing.rb', line 481

def has_skips?
    skip_count > 0
end

#has_tested?Boolean

Returns:

  • (Boolean)


493
494
495
# File 'lib/syskit/gui/testing.rb', line 493

def has_tested?
    @has_tested
end

#pendingObject



397
398
399
# File 'lib/syskit/gui/testing.rb', line 397

def pending
    self.background = Qt::Brush.new(Qt::Color.new(NEW_SLAVE_BACKGROUND))
end

#run_countObject



385
386
387
# File 'lib/syskit/gui/testing.rb', line 385

def run_count
    test_results.size
end

#runtimeObject



420
421
422
423
424
425
426
# File 'lib/syskit/gui/testing.rb', line 420

def runtime
    if @runtime
        @runtime
    elsif start_time
        Time.now - start_time
    end
end

#slave_failed?Boolean

Returns:

  • (Boolean)


477
478
479
# File 'lib/syskit/gui/testing.rb', line 477

def slave_failed?
    slave_exit_status && !slave_exit_status.success?
end

#slave_pid(pid) ⇒ Object



393
394
395
# File 'lib/syskit/gui/testing.rb', line 393

def slave_pid(pid)
    data(SLAVE_PID_ROLE).to_int
end

#slave_pid=(pid) ⇒ Object



389
390
391
# File 'lib/syskit/gui/testing.rb', line 389

def slave_pid=(pid)
    set_data(Qt::Variant.new(pid), SLAVE_PID_ROLE)
end

#startObject



409
410
411
412
413
414
415
416
417
418
# File 'lib/syskit/gui/testing.rb', line 409

def start
    @total_run_count += 1
    @start_time = Time.now
    @runtime = nil
    @executed = true
    @slave_exit_status = nil
    self.background = Qt::Brush.new(Qt::Color.new(RUNNING_BACKGROUND))
    clear
    update_text
end

#status_textObject



443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
# File 'lib/syskit/gui/testing.rb', line 443

def status_text
    text = []
    if has_tested?
        text << "#{test_results.size} runs, #{exception_count} exceptions, #{failure_count} failures and #{assertions_count} assertions"
    end

    if slave_exit_status && !slave_exit_status.success?
        if slave_exit_status.signaled?
            text << "Test process terminated with signal #{slave_exit_status.termsig}"
        elsif slave_exit_status.exitstatus != 1 || !has_tested? || (exception_count == 0 && failure_count == 0)
            text << "Test process finished with exit code #{slave_exit_status.exitstatus}"
        end
    end
    text
end

#test_finishedObject



474
475
# File 'lib/syskit/gui/testing.rb', line 474

def test_finished
end

#test_startObject



469
470
471
472
# File 'lib/syskit/gui/testing.rb', line 469

def test_start
    @has_tested = true
    update_text
end

#update_textObject



459
460
461
# File 'lib/syskit/gui/testing.rb', line 459

def update_text
    self.text = ([name] + status_text).join("\n")
end