Skip to content

Commit

Permalink
add tests of HpssFile
Browse files Browse the repository at this point in the history
  • Loading branch information
weaverba137 committed Jun 5, 2016
1 parent 6fc9440 commit 4012321
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 8 deletions.
6 changes: 2 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Compiled files
*.py[cod]

# C extensions
Expand All @@ -19,10 +20,6 @@ lib
lib64
__pycache__

# Other generated files
*/version.py
hpsspy/hpsspy.cfg

# Sphinx
_build
_static
Expand All @@ -32,6 +29,7 @@ _generated
pip-log.txt

# Unit test / coverage reports
htmlcov/
.coverage
.tox
nosetests.xml
Expand Down
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ hpsspy
:target: https://coveralls.io/github/weaverba137/hpsspy?branch=pre-0.3
:alt: Test Coverage Status

.. image:: https://readthedocs.org/projects/hpsspy/badge/?version=latest
:target: http://hpsspy.readthedocs.io/en/latest/?badge=latest
.. image:: https://readthedocs.org/projects/hpsspy/badge/?version=pre-0.3
:target: http://hpsspy.readthedocs.io/en/latest/?badge=pre-0.3
:alt: Documentation Status

Overview
Expand Down
50 changes: 49 additions & 1 deletion hpsspy/test/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@
from pkg_resources import resource_filename
import os
import sys
from ..util import get_hpss_dir, get_tmpdir, hsi, htar
import stat
import datetime
from .. import HpssOSError
from ..util import HpssFile, get_hpss_dir, get_tmpdir, hsi, htar


class TestUtil(unittest.TestCase):
Expand Down Expand Up @@ -51,6 +54,51 @@ def remove_bin(self, command):
os.remove(os.path.join(hpss_dir, 'bin', command))
os.rmdir(os.path.join(hpss_dir, 'bin'))

def test_HpssFile(self):
"""Test the HpssFile object.
"""
lspath = '/home/b/bweaver'
names = ('boss', 'cosmo', 'desi', 'test')
links = ('/nersc/projects/boss', '/nersc/projects/cosmo',
'/nersc/projects/desi', None)
modes = (0777, 0777, 0777, 02755)
mtimes = (datetime.datetime(2008, 4, 3, 0, 0, 0),
datetime.datetime(2014, 8, 22, 0, 0, 0),
datetime.datetime(2013, 12, 16, 0, 0, 0),
datetime.datetime(2016, 4, 4, 13, 14, 0))
data = (('l', 'rwxrwxrwx', '1', 'bweaver', 'bweaver',
'20', 'Apr', '3', '2008', 'boss@ -> /nersc/projects/boss'),
('l', 'rwxrwxrwx', '1', 'bweaver', 'bweaver',
'21', 'Aug', '22', '2014', 'cosmo@ -> /nersc/projects/cosmo'),
('l', 'rwxrwxrwx', '1', 'bweaver', 'bweaver',
'20', 'Dec', '16', '2013', 'desi@ -> /nersc/projects/desi'),
('d', 'rwxr-sr-x', '3', 'bweaver', 'bweaver',
'512', 'Apr', '4', '13:14', 'test'))
repr_template = ("HpssFile('{0}', '{1}', '{2}', '{3}', '{4}', " +
"'{5}', '{6}', '{7}', '{8}', '{9}', '{10}')")

files = list()
for d in data:
files.append(HpssFile(lspath, *d))
for i, f in enumerate(files):
r_data = [lspath] + list(data[i])
self.assertEqual(repr(f), repr_template.format(*r_data))
self.assertEqual(str(f), f.name)
self.assertEqual(f.name, names[i])
self.assertEqual(f.path, os.path.join(lspath, f.name))
# self.assertTrue(f.isdir)
m = f.st_mode
mt = f.st_mtime
if f.islink:
self.assertEqual(f.st_mode, modes[i] | stat.S_IFLNK)
self.assertEqual(f.readlink, links[i])
else:
self.assertTrue(f.isdir)
self.assertEqual(f.st_mode, modes[i] | stat.S_IFDIR)
with self.assertRaises(HpssOSError):
r = f.readlink
self.assertEqual(f.st_mtime, int(mtimes[i].strftime('%s')))

def test_get_hpss_dir(self):
"""Test searching for the HPSS_DIR variable.
"""
Expand Down
2 changes: 1 addition & 1 deletion hpsspy/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def isdir(self):
"""``True`` if the file is a directory or a symbolic link that
points to a directory.
"""
from .os import hpss_stat
from .os import stat as hpss_stat
if self.islink:
new_path = self.readlink
if new_path.startswith('/'):
Expand Down

0 comments on commit 4012321

Please sign in to comment.