コード例 #1
0
ファイル: test_section.py プロジェクト: hbradleyiii/ext_pylib
def test_section_is_in():
    """Test Section is_in method."""
    section_file = Section()
    section_file.read = utils.mock_read(SECTION_STR)
    assert section_file.is_in(FILE_HAS_SECTION_STR)
    assert section_file.is_in(FILE_WITH_SECTION_STR)
    assert not section_file.is_in(FILE_WITHOUT_SECTION_STR)
コード例 #2
0
ファイル: test_section.py プロジェクト: hbradleyiii/ext_pylib
def test_section_end_section_property():
    """Test Section end_section property."""
    section_file = Section()
    section_file.read = utils.mock_read(MULTILINE_STR)
    assert section_file.end_section == "This is the last line."
    section_file.read = utils.mock_read(MULTILINE_STR_WITH_RETURN)
    assert section_file.end_section == "This is the last line."
コード例 #3
0
ファイル: test_section.py プロジェクト: hbradleyiii/ext_pylib
def test_section_start_section_property_bad_section():
    """Test Section start_section property with invalid section data."""
    section_file = Section()
    section_file.read = utils.mock_read('')
    with pytest.raises(EOFError):
        assert section_file.start_section
    with pytest.raises(EOFError):
        assert section_file.end_section
コード例 #4
0
ファイル: test_section.py プロジェクト: hbradleyiii/ext_pylib
def test_section_is_in_bad_data():
    """Test Section is_in method passing in bad data."""
    section_file = Section()
    section_file.read = utils.mock_read(SECTION_STR)
    with pytest.raises(ValueError):
        assert section_file.is_in(FILE_BAD_SECTION_STR)
    with pytest.raises(ValueError):
        assert section_file.is_in(FILE_BAD_SECTION2_STR)
コード例 #5
0
ファイル: test_section.py プロジェクト: hbradleyiii/ext_pylib
def test_section_apply_to():
    """Test Section apply_to method."""
    section_file = Section()
    section_file.read = utils.mock_read(SECTION_STR)
    assert section_file.apply_to(FILE_WITH_SECTION_STR) == FILE_WITH_SECTION_STR
    assert section_file.apply_to(FILE_WITHOUT_SECTION_STR) == FILE_WITHOUT_SECTION_STR + '\n' + SECTION_STR + '\n'
    with pytest.raises(ValueError):
        section_file.apply_to(FILE_HAS_SECTION_STR, overwrite=False)
    assert section_file.apply_to(FILE_HAS_SECTION_STR, overwrite=True) == FILE_WITH_SECTION_STR