Beispiel #1
0
    def test_db_migration(self):
        ORIG_CONFIG_DIR = autojump.CONFIG_DIR
        try:
            # setup
            CONFIG_DIR = '/tmp/autojump_test_db_load_migrate_' + str(random.randint(0,32678))
            os.mkdir(CONFIG_DIR)
            autojump.CONFIG_DIR = CONFIG_DIR
            fname = CONFIG_DIR + '/autojump_py'
            db = autojump.Database(fname)
            db.add('/1')
            db.add('/2')
            shutil.copy(fname, fname + '.bak')

            # test
            missing_fname = '/tmp/autojump_test_db_load_missing_' + str(random.randint(0,32678)) + '.txt'
            db = autojump.Database(missing_fname)

            db.add('/3')
            self.assertEquals(len(db.data), 3)

        finally:
            # teardown
            shutil.rmtree(CONFIG_DIR)
            os.remove(missing_fname)
            os.remove(missing_fname + '.bak')

            autojump.CONFIG_DIR = ORIG_CONFIG_DIR
Beispiel #2
0
    def setUp(self):
        autojump.CONFIG_DIR = tempfile.mkdtemp()
        autojump.TESTING = True
        self.fd, self.fname = tempfile.mkstemp()
        self.db = autojump.Database(self.fname)

        random.seed()
Beispiel #3
0
    def test_db_load_backup(self):
        # setup
        fname = '/tmp/autojump_test_db_load_backup_' + str(random.randint(0,32678))
        db = autojump.Database(fname)
        db.add('/1')
        os.rename(fname, fname + '.bak')

        try:
            # test
            with no_stderr():
                db = autojump.Database(fname)
            self.assertTrue(len(db.data) > 0)
            self.assertTrue(os.path.isfile(fname))
        finally:
            # teardown
            os.remove(fname)
            os.remove(fname + '.bak')
Beispiel #4
0
    def test_db_load_empty(self):
        # setup
        _, fname = tempfile.mkstemp()
        db = autojump.Database(fname)

        try:
            # test
            self.assertEquals(len(self.db), 0)
        finally:
            # teardown
            os.remove(fname)
Beispiel #5
0
    def test_db_save(self):
        # setup
        fname = '/tmp/autojump_test_db_save_' + str(random.randint(0,32678)) + '.txt'
        db = autojump.Database(fname)

        try:
            # test
            db.save()
            self.assertTrue(os.path.isfile(fname))
        finally:
            # teardown
            os.remove(fname)
            os.remove(fname + '.bak')
Beispiel #6
0
 def test_db_load_existing(self):
     self.db = autojump.Database('tests/database.txt')
     self.assertTrue(len(self.db) > 0)