Skip to content

Commit

Permalink
Change name of utils.verify_path to utils.prepare_path
Browse files Browse the repository at this point in the history
Better reflects its intent
  • Loading branch information
Petter Johansson committed Dec 9, 2014
1 parent 52b1195 commit 29932e0
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 20 deletions.
18 changes: 9 additions & 9 deletions pygromacs/gmxfiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import os
from contextlib import redirect_stdout
from pygromacs.utils import verify_path
from pygromacs.utils import prepare_path

"""Interfaces for reading and modifying Gromacs standard files."""

Expand All @@ -18,7 +18,7 @@ class MdpFile(object):
"""Container for MDP files.
Args:
path (str): Read from file at this path (optional)
path (str, optional): Read from file at this path
Attributes:
path: Path to the last-read file. Used as default by :func:`save`
Expand Down Expand Up @@ -95,7 +95,7 @@ def get_option(self, parameter):

return value

def set_comment(self, parameter, comment=""):
def set_comment(self, parameter, comment):
"""Add a comment to a parameter."""

if parameter not in self.options.keys():
Expand All @@ -116,7 +116,7 @@ def set_option(self, parameter, value, comment=""):
Args:
parameter (str): A parameter to set,
value (str): its new value
comment (str): and comment (optional)
comment (str, optional): and comment
"""

Expand Down Expand Up @@ -173,7 +173,7 @@ def print(self, comment=True):
"""Print the current file.
Args:
comment (bool): Print or ignore comments
comment (bool, optional): Print or ignore comments
"""

Expand Down Expand Up @@ -231,9 +231,9 @@ def save(self, path="", verbose=True, ext='mdp'):
The written content is set in :attr:`lines`.
Args:
path (str): Write file to this path (by default to :attr:`path`)
verbose (bool): Print information about save
ext (str): Use this file extension (by default 'mdp')
path (str, optional): Write file to this path (default: :attr:`path`)
verbose (bool, optional): Print information about save
ext (str, optional): Use this file extension (default: 'mdp')
"""

Expand All @@ -245,7 +245,7 @@ def save(self, path="", verbose=True, ext='mdp'):
path = '.'.join([path, ext])

# Verify path and backup collision
verify_path(path, verbose)
prepare_path(path, verbose)

# Actually save the file
with open(path, 'w') as fp:
Expand Down
10 changes: 5 additions & 5 deletions pygromacs/tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
from pygromacs.utils import *

def test_verify_path():
def test_prepare_path():
path = 'pygromacs/tests/grompp.mdp'
directory, filename = os.path.split(path)
bkpfile = "#%s.1#" % filename

backup = verify_path('')
backup = prepare_path('')
assert (backup == "")
backup = verify_path(path)
backup = prepare_path(path)
assert (backup == os.path.join(directory, bkpfile))
assert (os.access(backup, os.F_OK) == True)
os.rename(backup, path)

# Test creation of a new directory
newdir = os.path.join(directory, 'verify_path_test')
backup = verify_path(os.path.join(newdir, filename))
newdir = os.path.join(directory, 'prepare_path_test')
backup = prepare_path(os.path.join(newdir, filename))
assert (backup == "")
assert (os.path.isdir(newdir) == True)
os.rmdir(newdir)
12 changes: 6 additions & 6 deletions pygromacs/utils.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import os

def verify_path(path, verbose=True):
"""
Verify that a location exists by creating required directories and
back up any conflicting file.
def prepare_path(path, verbose=True):
"""Prepare a path for writing.
Creates required directories and backs up any conflicting file.
Args:
path (str): Path to file
verbose (bool): Whether or not to print information about
a performed backup
verbose (bool, optional): Whether or not to print information
about a performed backup
Returns:
str: The path to a backed up file, empty if no backup was taken
Expand Down

0 comments on commit 29932e0

Please sign in to comment.