コード例 #1
0
ファイル: test_dir.py プロジェクト: hbradleyiii/ext_pylib
def test_dir_fill(mock_copytree, mock_exists):
    """Tests filling one Dir with another."""
    mock_exists.return_value = True
    the_dir = Dir({'path' : '/test/dir/'})
    fill_with = Dir({'path' : '/another/test/dir/'})
    assert the_dir.fill(fill_with)
    mock_copytree.assert_called_once_with('/another/test/dir/', '/test/dir/')
コード例 #2
0
ファイル: test_dir.py プロジェクト: hbradleyiii/ext_pylib
def test_dir_create(mock_makedirs, mock_exists, mock_chmod, mock_chown):
    """Test directory creation."""
    mock_exists.return_value = False
    mock_chown.return_value = mock_chmod.return_value = True
    the_dir = Dir({'path' : '/test/dir/'})
    assert the_dir.create()
    mock_makedirs.assert_called_once_with('/test/dir/')
コード例 #3
0
ファイル: test_dir.py プロジェクト: hbradleyiii/ext_pylib
def test_dir_remove_nonexisting(mock_rmtree, mock_exists):
    """Test non-existing directory removal."""
    mock_exists.return_value = False
    the_dir = Dir({'path' : '/test/dir/'})
    the_dir2 = Dir({'path' : None})
    assert the_dir.remove(False)
    assert the_dir2.remove(False)
    assert not mock_rmtree.called
コード例 #4
0
def root(request):
    """Sets up a root directory to use for testing."""
    root_dir = Dir({"path": "/tmp/ext_pylib/" + datetime.now().strftime("%Y-%m-%d--%H-%M-%S")})
    assert root_dir.remove(False)  # If it already exists, remove it.
    assert root_dir.create()
    assert root_dir.exists()

    def cleanup():
        """Removes created test root directory."""
        assert root_dir.remove(False)
        assert not root_dir.exists()

    request.addfinalizer(cleanup)

    return root_dir
コード例 #5
0
def test_section_file_apply_to_file():
    """[Integration Test] Test apply_to_file() method of Section class."""
    # Setup a root dir to use to test
    root_dir = Dir({"path": "/tmp/ext_pylib/"})
    assert root_dir.remove(False)  # If it already exists, remove it.
    assert root_dir.create()
    assert root_dir.exists()

    file_without_section = File({"path": "/tmp/ext_pylib/file"})
    assert file_without_section.create()
    assert file_without_section.overwrite(FILE_CONTENTS_WITHOUT_SECTION)
    assert file_without_section.exists()

    class SectionFile(Section, File):
        """Dummy Class extending Section and File."""

    section = SectionFile({"path": "/tmp/ext_pylib/section"})
    assert section.create()
    assert section.overwrite(SECTION_FILE_CONTENTS)
    assert section.exists()

    file_with_section = File({"path": "/tmp/ext_pylib/file_with_section"})
    assert file_with_section.create()
    assert file_with_section.overwrite(FILE_CONTENTS_WITH_SECTION)
    assert file_with_section.exists()

    assert section.is_in(file_with_section.read())
    print("Without:")
    print(file_without_section.read())
    print("Without (Applied):")
    print(section.apply_to(file_without_section.read()))
    print("With:")
    print(file_with_section.read())
    assert section.apply_to(file_without_section.read()) == file_with_section.read()

    # Cleanup
    assert root_dir.remove(False)
    assert not root_dir.exists()
コード例 #6
0
ファイル: test_dir.py プロジェクト: hbradleyiii/ext_pylib
def test_dir_remove(mock_rmtree, mock_exists):
    """Test directory removal."""
    mock_exists.return_value = True
    the_dir = Dir({'path' : '/test/dir/'})
    assert the_dir.remove(False)
    mock_rmtree.assert_called_once_with('/test/dir/')
コード例 #7
0
ファイル: test_dir.py プロジェクト: hbradleyiii/ext_pylib
def test_dir_create_existing(mock_makedirs, mock_exists):
    """Test creating dir when it already exists."""
    mock_exists.return_value = True
    the_dir = Dir({'path' : '/test/dir/'})
    assert the_dir.create()
    assert not mock_makedirs.called
コード例 #8
0
def test_dir_actual_create_and_remove():
    """[Integration Test] Test actual creation and removal of directory."""
    # Setup a root dir to use to test
    root_dir = Dir({"path": "/tmp/ext_pylib/"})
    assert root_dir.remove(False)  # If it already exists, remove it.
    assert root_dir.create()
    assert root_dir.exists()

    # Perform a (redundant) creation test
    the_dir = Dir({"path": "/tmp/ext_pylib/" + datetime.now().strftime("%Y-%m-%d--%H-%M-%S") + "/path/dir"})
    assert not the_dir.exists()
    assert the_dir.create()
    assert the_dir.exists()

    # Perform a removal test
    assert the_dir.remove(False)
    assert not the_dir.exists()

    # Cleanup
    assert root_dir.remove(False)
    assert not root_dir.exists()