summary refs log blame commit diff stats
path: root/test/tc_bookmarks.py
blob: f45ba0614fe9299cc23a477cace19feb11b4d11c (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15














                                                                       








































































                                                                 
# Copyright (C) 2009, 2010  Roman Zimbelmann <romanz@lavabit.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

if __name__ == '__main__': from __init__ import init; init()

from os.path import realpath, join, dirname
import unittest
import os
import time

from ranger.container.bookmarks import Bookmarks

TESTDIR = realpath(join(dirname(__file__), 'testdir'))
BMFILE = join(TESTDIR, 'bookmarks')

class TestDisplayable(unittest.TestCase):
	def setUp(self):
		try:
			os.remove(BMFILE)
		except:
			pass

	def tearDown(self):
		try:
			os.remove(BMFILE)
		except:
			pass
	
	def test_adding_bookmarks(self):
		bm = Bookmarks(BMFILE, str, autosave=False)
		bm.load()
		bm['a'] = 'fooo'
		self.assertEqual(bm['a'], 'fooo')

	def test_sharing_bookmarks_between_instances(self):
		bm = Bookmarks(BMFILE, str, autosave=True)
		bm2 = Bookmarks(BMFILE, str, autosave=True)

		bm.load()
		bm2.load()
		bm['a'] = 'fooo'
		self.assertRaises(KeyError, bm2.__getitem__, 'a')

		bm.save()
		bm2.load()
		self.assertEqual(bm['a'], bm2['a'])

		bm2['a'] = 'bar'

		bm.save()
		bm2.save()
		bm.load()
		bm2.load()

		self.assertEqual(bm['a'], bm2['a'])
	
	def test_messing_around(self):
		bm = Bookmarks(BMFILE, str, autosave=False)
		bm2 = Bookmarks(BMFILE, str, autosave=False)

		bm.load()
		bm['a'] = 'car'

		bm2.load()
		self.assertRaises(KeyError, bm2.__getitem__, 'a')

		bm2.save()
		bm.update()
		bm.save()
		bm.load()
		bm2.load()

		self.assertEqual(bm['a'], bm2['a'])

if __name__ == '__main__':
	unittest.main()
n class="w"> ex5.out` = 'a' test `uname` = 'Linux' && { echo a | examples/ex5 >ex5.out || true test `cat ex5.out` = 'a' } echo ex6 CFLAGS=-g ./subx translate examples/ex6.subx -o examples/ex6 git diff --quiet examples/ex6 CFLAGS=-g ./subx run examples/ex6 >ex6.out || true test "`cat ex6.out`" = 'Hello, world!' test `uname` = 'Linux' && { examples/ex6 >ex6.out || true test "`cat ex6.out`" = 'Hello, world!' } echo ex7 CFLAGS=-g ./subx translate examples/ex7.subx -o examples/ex7 git diff --quiet examples/ex7 CFLAGS=-g ./subx run examples/ex7 || ret=$? test $ret -eq 97 # 'a' test `uname` = 'Linux' && { examples/ex7 || ret=$? test $ret -eq 97 # 'a' } echo ex8 CFLAGS=-g ./subx translate examples/ex8.subx -o examples/ex8 [ "$1" != record ] && git diff --quiet examples/ex8 CFLAGS=-g ./subx run examples/ex8 abcd || ret=$? test $ret -eq 4 # length('abcd') test `uname` = 'Linux' && { examples/ex8 abcd || ret=$? test $ret -eq 4 # length('abcd') } echo ex9 CFLAGS=-g ./subx translate examples/ex9.subx -o examples/ex9 [ "$1" != record ] && git diff --quiet examples/ex9 CFLAGS=-g ./subx run examples/ex9 z x || ret=$? test $ret -eq 2 # 'z' - 'x' test `uname` = 'Linux' && { examples/ex9 z x || ret=$? test $ret -eq 2 # 'z' - 'x' } echo ex10 CFLAGS=-g ./subx translate examples/ex10.subx -o examples/ex10 [ "$1" != record ] && git diff --quiet examples/ex10 CFLAGS=-g ./subx run examples/ex10 abc abc || ret=$? test $ret -eq 1 # equal CFLAGS=-g ./subx run examples/ex10 abc abcd # 0; not equal test `uname` = 'Linux' && { examples/ex10 abc abc || ret=$? test $ret -eq 1 # equal examples/ex10 abc abcd # 0; not equal } echo ex11 CFLAGS=-g ./subx translate examples/ex11.subx -o examples/ex11 [ "$1" != record ] && git diff --quiet examples/ex11 CFLAGS=-g ./subx run examples/ex11 echo test `uname` = 'Linux' && { examples/ex11 echo } echo ex12 CFLAGS=-g ./subx translate examples/ex12.subx -o examples/ex12 [ "$1" != record ] && git diff --quiet examples/ex12 CFLAGS=-g ./subx run examples/ex12 # final byte of mmap'd address is well-nigh guaranteed to be 0 test `uname` = 'Linux' && examples/ex12 echo handle CFLAGS=-g ./subx translate *.subx apps/handle.subx -o apps/handle [ "$1" != record ] && git diff --quiet apps/handle CFLAGS=-g ./subx run apps/handle 2>&1 |grep -q 'lookup failed' echo test `uname` = 'Linux' && { apps/handle test 2>&1 |grep -q 'lookup failed' echo } echo factorial CFLAGS=-g ./subx translate *.subx apps/factorial.subx -o apps/factorial [ "$1" != record ] && git diff --quiet apps/factorial CFLAGS=-g ./subx run apps/factorial || ret=$? test $ret -eq 120 # factorial(5) CFLAGS=-g ./subx run apps/factorial test echo test `uname` = 'Linux' && { apps/factorial || ret=$? test $ret -eq 120 # factorial(5) apps/factorial test echo } echo crenshaw2-1 CFLAGS=-g ./subx translate *.subx apps/crenshaw2-1.subx -o apps/crenshaw2-1 [ "$1" != record ] && git diff --quiet apps/crenshaw2-1 CFLAGS=-g ./subx run apps/crenshaw2-1 test echo test `uname` = 'Linux' && { apps/crenshaw2-1 test echo } echo crenshaw2-1b CFLAGS=-g ./subx translate *.subx apps/crenshaw2-1b.subx -o apps/crenshaw2-1b [ "$1" != record ] && git diff --quiet apps/crenshaw2-1b CFLAGS=-g ./subx run apps/crenshaw2-1b test echo test `uname` = 'Linux' && { apps/crenshaw2-1b test echo } echo hex CFLAGS=-g ./subx translate *.subx apps/hex.subx -o apps/hex [ "$1" != record ] && git diff --quiet apps/hex CFLAGS=-g ./subx run apps/hex test echo test `uname` = 'Linux' && { apps/hex test echo } exit 0