Пример #1
0
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
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
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
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
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