Project

General

Profile

« Previous | Next » 

Revision bd588eb9

Added by koszko over 1 year ago

add missing english translations and verify message texts of raised exceptions in tests

View differences:

tests/test_build.py
582 582
    Modify index.json to expect missing report.spdx file and cause an error.
583 583
    """
584 584
    monkeypatch.delitem(index_obj, 'reuse_generate_spdx_report')
585
    return FileNotFoundError
585
    return FileNotFoundError,
586 586

  
587 587
@error_maker
588 588
def sample_source_error_index_schema(monkeypatch, sample_source):
589 589
    """Modify index.json to be incompliant with the schema."""
590 590
    monkeypatch.delitem(index_obj, 'definitions')
591
    return ValidationError
591
    return ValidationError,
592 592

  
593 593
@error_maker
594 594
def sample_source_error_bad_comment(monkeypatch, sample_source):
595 595
    """Modify index.json to have an invalid '/' in it."""
596
    return json.JSONDecodeError, json.dumps(index_obj) + '/something\n'
596
    return json.JSONDecodeError, '^bad_comment: .*', \
597
        json.dumps(index_obj) + '/something\n'
597 598

  
598 599
@error_maker
599 600
def sample_source_error_bad_json(monkeypatch, sample_source):
600 601
    """Modify index.json to not be valid json even after comment stripping."""
601
    return json.JSONDecodeError, json.dumps(index_obj) + '???/\n'
602
    return json.JSONDecodeError, '', json.dumps(index_obj) + '???\n'
602 603

  
603 604
@error_maker
604 605
def sample_source_error_missing_reuse(monkeypatch, sample_source):
605 606
    """Cause mocked reuse process invocation to fail with FileNotFoundError."""
606 607
    (sample_source / 'mock_reuse_missing').touch()
607
    return build.ReuseError
608
    return build.ReuseError, '^couldnt_execute_reuse_is_it_installed$'
608 609

  
609 610
@error_maker
610 611
def sample_source_error_missing_license(monkeypatch, sample_source):
611 612
    """Remove a file to make package REUSE-incompliant."""
612 613
    (sample_source / 'README.txt.license').unlink()
613
    return build.ReuseError
614

  
615
    error_regex = """^\
616
command_reuse --root \\S+ lint_failed
617

  
618
STDOUT_OUTPUT_heading
619

  
620
dummy lint output
621

  
622
STDERR_OUTPUT_heading
623

  
624
some error output\
625
$\
626
"""
627

  
628
    return build.ReuseError, error_regex
614 629

  
615 630
@error_maker
616 631
def sample_source_error_file_outside(monkeypatch, sample_source):
617 632
    """Make index.json illegally reference a file outside srcdir."""
618 633
    new_list = [*index_obj['copyright'], {'file': '../abc'}]
619 634
    monkeypatch.setitem(index_obj, 'copyright', new_list)
620
    return FileReferenceError
635
    return FileReferenceError, '^path_contains_double_dot_\\.\\./abc$'
621 636

  
622 637
@error_maker
623 638
def sample_source_error_reference_itself(monkeypatch, sample_source):
624 639
    """Make index.json illegally reference index.json."""
625 640
    new_list = [*index_obj['copyright'], {'file': 'index.json'}]
626 641
    monkeypatch.setitem(index_obj, 'copyright', new_list)
627
    return FileReferenceError
642
    return FileReferenceError, '^loading_reserved_index_json$'
628 643

  
629 644
@error_maker
630 645
def sample_source_error_report_excluded(monkeypatch, sample_source):
......
635 650
    new_list = [file_ref for file_ref in index_obj['copyright']
636 651
                if file_ref['file'] != 'report.spdx']
637 652
    monkeypatch.setitem(index_obj, 'copyright', new_list)
638
    return FileReferenceError
653
    return FileReferenceError, '^report_spdx_not_in_copyright_list$'
639 654

  
640 655
@pytest.fixture(params=error_makers)
641 656
def sample_source_make_errors(request, monkeypatch, sample_source):
......
644 659
    broken versions. Return an error type that should be raised when running
645 660
    test build.
646 661
    """
647
    index_text = None
648
    error_type = request.param(monkeypatch, sample_source)
649
    if type(error_type) is tuple:
650
        error_type, index_text = error_type
662
    error_type, error_regex, index_text = \
663
        [*request.param(monkeypatch, sample_source), '', ''][0:3]
651 664

  
652 665
    index_text = index_text or json.dumps(index_obj)
653 666

  
......
655 668

  
656 669
    monkeypatch.setitem(src_files, 'index.json', index_text.encode())
657 670

  
658
    return error_type
671
    return error_type, error_regex
659 672

  
660 673
@pytest.mark.subprocess_run(build, run_reuse)
661 674
@pytest.mark.usefixtures('mock_subprocess_run')
662 675
def test_build_error(tmpdir, sample_source, sample_source_make_errors):
663 676
    """Try building the sample source package and verify generated errors."""
664
    error_type = sample_source_make_errors
677
    error_type, error_regex = sample_source_make_errors
665 678

  
666 679
    dstdir = Path(tmpdir) / 'dstdir'
667 680
    tmpdir = Path(tmpdir) / 'example'
......
669 682
    dstdir.mkdir(exist_ok=True)
670 683
    tmpdir.mkdir(exist_ok=True)
671 684

  
672
    with pytest.raises(error_type):
685
    with pytest.raises(error_type, match=error_regex):
673 686
        build.Build(sample_source, Path('index.json'))\
674 687
             .write_package_files(dstdir)

Also available in: Unified diff