Skip to content

Commit

Permalink
Fixes #14.
Browse files Browse the repository at this point in the history
Removed 'location' keyword from Treant init. Also removed init method
from Group and therefore the ability to add members through the
constructor. This comes with the advantage of not having to edit Treant
children whenever the init method changes.

It's now no longer necessary to use a separate keyword to put a Treant
in another directory. What used to be it's 'name' is now just the path
to the Treant, which will always include its name (the basedir of the
statefile). This simplifies creating and reloading Treants, since the
same syntax works for both. See the documentation for the constructor
for the details.
  • Loading branch information
dotsdl committed Sep 8, 2015
1 parent 6b6ca14 commit 6a5294d
Show file tree
Hide file tree
Showing 4 changed files with 133 additions and 130 deletions.
8 changes: 0 additions & 8 deletions datreant/persistence.py
Original file line number Diff line number Diff line change
Expand Up @@ -740,8 +740,6 @@ def __init__(self, filename, logger=None, **kwargs):
:Keywords:
*treanttype*
Treant type
*name*
user-given name of Treant object
*coordinator*
directory in which coordinator state file can be found [None]
*categories*
Expand Down Expand Up @@ -772,8 +770,6 @@ def create(self, **kwargs):
"""Build state file and common data structure elements.
:Keywords:
*name*
user-given name of Treant object
*coordinator*
directory in which coordinator state file can be found [None]
*categories*
Expand Down Expand Up @@ -1119,8 +1115,6 @@ def __init__(self, filename, logger=None, **kwargs):
logger to send warnings and errors to
:Keywords:
*name*
user-given name of Treant object
*coordinator*
directory in which coordinator state file can be found [None]
*categories*
Expand All @@ -1136,8 +1130,6 @@ def create(self, **kwargs):
"""Build Group data structure.
:Keywords:
*name*
user-given name of Group object
*coordinator*
directory in which Coordinator state file can be found [``None``]
*categories*
Expand Down
2 changes: 1 addition & 1 deletion datreant/tests/test_bundle.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def test_remove_members_name(self, collection, tmpdir):
"""Try removing members with names and globbing"""
with tmpdir.as_cwd():
t1 = dtr.Treant('lark')
t2 = dtr.Treant('lark', location='elsewhere')
t2 = dtr.Treant('elsewhere/lark')
t3 = dtr.Treant('hark')
g = dtr.Group('linus')

Expand Down
85 changes: 85 additions & 0 deletions datreant/tests/test_treants.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,60 @@ def test_init(self, treant, tmpdir):
assert treant.treanttype == self.treanttype
assert treant.basedir == os.path.join(tmpdir.strpath, self.treantname)

def test_gen_methods(self, tmpdir):
"""Test the variety of ways we can generate a new Treant
1. `Treant('treant')`, where 'treant' is not an existing file or
directory path
2. `Treant('treant')`, where 'treant' is an existing
directory without Treant state files inside
3. `Treant('/somedir/treant')`, where 'treant' is not an existing
file or directory in 'somedir'
4. `Treant('/somedir/treant')`, where 'treant' is an existing directory
in 'somedir' without any Treant state files inside
5. `Treant('somedir/treant', new=True)`, where 'treant' is an existing
directory in 'somedir' with an existing Treant statefile
6. `Treant('/somedir/treant')`, where 'treant' is an existing directory
in 'somedir' with other types of Treant files inside (such as Group)
"""
with tmpdir.as_cwd():
# 1
t1 = self.treantclass('newone')
assert os.path.exists(t1.filepath)

# 2
os.mkdir('another')
t2 = self.treantclass('another')
assert os.path.exists(t2.filepath)

# 3
t3 = self.treantclass('yet/another')
assert os.path.exists(t3.filepath)

# 4
os.mkdir('yet/more')
t4 = self.treantclass('yet/more')
assert os.path.exists(t4.filepath)

# 5
t5 = self.treantclass('yet/more', new=True)
assert os.path.exists(t5.filepath)
assert t5.basedir == t4.basedir
assert t5.filepath != t4.filepath

# 6
compare = t1.uuid
os.rename(t1.filepath,
t1.filepath.replace(t1.treanttype, 'Another'))
t6 = self.treantclass('newone')
assert t6.uuid != compare

def test_regen(self, tmpdir):
"""Test regenerating Treant.
Expand All @@ -49,6 +103,37 @@ def test_regen(self, tmpdir):
# they point to the same file, but they are not the same object
assert C1 is not C2

def test_regen_methods(self, tmpdir):
"""Test the variety of ways Treants can be regenerated.
"""
with tmpdir.as_cwd():
t1 = self.treantclass('newone')
t2 = self.treantclass('newone')
assert t1.uuid == t2.uuid

t3 = self.treantclass('newone', new=True)
assert t3.uuid != t2.uuid

t4 = self.treantclass(t3.filepath)
assert t4.uuid == t3.uuid

def test_noregen(self, tmpdir):
"""Test a variety of ways that generation of a new Treant should fail.
1. `Treant('somedir/treant')` should raise `MultipleTreantsError` if
more than one state file is in the given directory
"""
with tmpdir.as_cwd():
# 1
t1 = self.treantclass('newone')
t2 = self.treantclass('newone', new=True)
assert t1.uuid != t2.uuid

with pytest.raises(dtr.treants.MultipleTreantsError):
t3 = self.treantclass('newone')

def test_cmp(self, tmpdir):
"""Test the comparison of Treants when sorting"""
with tmpdir.as_cwd():
Expand Down

0 comments on commit 6a5294d

Please sign in to comment.