Esempio n. 1
0
def test_section_not_exists_no_section(mocked_updater_class):
    mock_file = Mock()
    expected_path = Mock()
    expected_path.open.return_value.__enter__ = Mock(return_value=mock_file)
    expected_path.open.return_value.__exit__ = Mock()

    expected_section = Mock()

    mocked_updater = MagicMock()
    mocked_updater.has_section.return_value = False

    mocked_updater_class.return_value = mocked_updater

    rule = SectionNotExists(name="Section not exists rule",
                            path=expected_path,
                            section=expected_section)

    result = rule.task()

    mocked_updater.has_section.assert_called_once_with(expected_section)
    assert mocked_updater.remove_section.called is False
    assert result == expected_path
Esempio n. 2
0
def test_section_not_exists(temporary_file):
    expected_file = Path(temporary_file.name)
    expected_file.write_text("[main]\n[remains]")

    rule = SectionNotExists(name="Ensure section not exists",
                            path=expected_file,
                            section="main")

    rule.pre_task_hook()
    rule.task()

    assert expected_file.read_text() == "[remains]"
    expected_file.unlink()
Esempio n. 3
0
def test_section_not_exists_no_section_match(temporary_file):
    expected_file = Path(temporary_file.name)
    expected_file.write_text("[main]")

    rule = SectionNotExists(
        name="Ensure section not exists",
        path=expected_file,
        section="remove_me_if_you_can",
    )

    rule.pre_task_hook()
    rule.task()

    assert expected_file.read_text() == "[main]"
    expected_file.unlink()