Skip to content

Commit

Permalink
adds unit test for export function
Browse files Browse the repository at this point in the history
  • Loading branch information
mjgiarlo committed Oct 2, 2009
1 parent a73b9d8 commit 35018ac
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 11 deletions.
4 changes: 0 additions & 4 deletions dflat.py
Expand Up @@ -142,7 +142,6 @@ def export(home, version):
# copy the latest version
current_version = _current_version(home)
export = 'export-%s' % version
print "would export to %s" % export
shutil.copytree(j(home, current_version), j(home, export))
# walk back from latest version-1 to specified version, applying changes
delta_versions = _versions(home,
Expand All @@ -155,16 +154,13 @@ def export(home, version):
if isfile(j(home, dv, 'redd', 'delete.txt')):
deletes = open(j(home, dv, 'redd', 'delete.txt')).read().split()
for delete in deletes:
print "deleting: %s" % j(home, export, 'full', delete)
remove(j(home, export, 'full', delete))
# add added files
if isdir(j(home, dv, 'redd', 'add')):
for f in listdir(j(home, dv, 'redd', 'add')):
print "copying %s to %s" % (j(home, dv, 'redd', 'add', f), j(home, export, 'full', f))
copy_tree(j(home, dv, 'redd', 'add', f), j(home, export, 'full', f))
logging.info('exported version %s' % version)

@lock
def status(home):
print "dflat home: %s" % home
v1 = _current_version(home)
Expand Down
62 changes: 55 additions & 7 deletions test.py
Expand Up @@ -15,7 +15,7 @@ def setUp(self):

def tearDown(self):
if isdir('dflat-test'):
pass #rmtree('dflat-test')
rmtree('dflat-test')

def test_init(self):
dflat.init('dflat-test')
Expand Down Expand Up @@ -104,12 +104,9 @@ def test_status(self):

def test_locking(self):
# create named function objects to test user-agent func
def init():
pass
def checkout():
pass
def commit():
pass
def init(): pass
def checkout(): pass
def commit(): pass
# open the lockfile and spit out, e.g.:
# ["Lock:", "2009-08-10T09:09:09.000000", "dflat-init"]
def contents(f):
Expand Down Expand Up @@ -147,4 +144,55 @@ def contents(f):
dflat._release_lock('dflat-test')
self.assertFalse(isfile(lockfile))

def test_export(self):
home = 'dflat-test'
dflat.init(home)
# create v002
dflat.checkout(home)
open('dflat-test/v002/full/data/reddspec.html', 'a').write('mod')
# commit v002
dflat.commit(home)
# create v003
dflat.checkout(home)
open('dflat-test/v003/full/data/newfile.txt', 'w').write('newfile')
# commit v003
dflat.commit(home)
# create v004
dflat.checkout(home)
remove('dflat-test/v004/full/data/dflatspec.pdf')
# commit v004
dflat.commit(home)
# create v005
dflat.checkout(home)
# commit v005
dflat.commit(home)
# export an invalid version
self.assertRaises(Exception, dflat.export, home, 'v000')
# export v004 and check it
dflat.export(home, "v004")
self.assertTrue(isdir('dflat-test/export-v004'))
self.assertFalse(isfile('dflat-test/export-v004/full/data/dflatspec.pdf'))
self.assertEqual(open('dflat-test/export-v004/full/data/reddspec.html').read(),
open('dflat-test/v005/full/data/reddspec.html').read())
# export v003 and check it
dflat.export(home, "v003")
self.assertTrue(isdir('dflat-test/export-v003'))
self.assertTrue(isfile('dflat-test/export-v003/full/data/newfile.txt'))
self.assertTrue(isfile('dflat-test/export-v003/full/data/dflatspec.pdf'))
self.assertEqual(open('dflat-test/export-v003/full/data/reddspec.html').read(),
open('dflat-test/v005/full/data/reddspec.html').read())
# export v002 and check it
dflat.export(home, "v002")
self.assertTrue(isdir('dflat-test/export-v002'))
self.assertFalse(isfile('dflat-test/export-v002/full/data/newfile.txt'))
self.assertTrue(isfile('dflat-test/export-v002/full/data/dflatspec.pdf'))
self.assertEqual(open('dflat-test/export-v002/full/data/reddspec.html').read(),
open('dflat-test/v005/full/data/reddspec.html').read())
# export v001 and check it
dflat.export(home, "v001")
self.assertTrue(isdir('dflat-test/export-v001'))
self.assertFalse(isfile('dflat-test/export-v001/full/data/newfile.txt'))
self.assertTrue(isfile('dflat-test/export-v001/full/data/dflatspec.pdf'))
self.assertNotEqual(open('dflat-test/export-v001/full/data/reddspec.html').read(),
open('dflat-test/v005/full/data/reddspec.html').read())

0 comments on commit 35018ac

Please sign in to comment.