コード例 #1
0
ファイル: file_test.py プロジェクト: QuLogic/gramps
    def test_mediapath(self):
        """
        Test media path variables.
        """

        # Create database
        dbstate = DbState()
        db = dbstate.make_database("bsddb")
        path = get_empty_tempdir("utils_file_test")
        db.write_version(path)
        db.load(path)
        dbstate.change_database(db)

        # Test without db.mediapath set
        self.assertEqual(media_path(db), os.path.normcase(os.path.normpath(os.path.abspath(USER_HOME))))
        self.assertTrue(os.path.exists(media_path(db)))

        # Test with absolute db.mediapath
        db.set_mediapath(os.path.abspath(USER_HOME) + "/test_abs")
        self.assertEqual(media_path(db), os.path.normcase(os.path.normpath(os.path.abspath(USER_HOME + "/test_abs"))))

        # Test with relative db.mediapath
        db.set_mediapath("test_rel")
        self.assertEqual(
            media_path(db), os.path.normcase(os.path.normpath(os.path.abspath(TEMP_DIR + "/utils_file_test/test_rel")))
        )

        # Test with environment variable
        db.set_mediapath("/test/{VERSION}/test_var")
        self.assertEqual(
            media_path(db), os.path.normcase(os.path.normpath(os.path.abspath("/test/" + VERSION + "/test_var")))
        )
        db.set_mediapath("{USER_PLUGINS}/test_var")
        self.assertEqual(
            media_path(db), os.path.normcase(os.path.normpath(os.path.abspath(USER_PLUGINS + "/test_var")))
        )
        db.set_mediapath("{VERSION}/test_var")
        self.assertEqual(
            media_path(db),
            os.path.normcase(os.path.normpath(os.path.abspath(TEMP_DIR + "/utils_file_test/" + VERSION + "/test_var"))),
        )

        # Test with $GRAMPSHOME environment variable not set
        old_env = os.environ.copy()
        if "GRAMPSHOME" in os.environ:
            del os.environ["GRAMPSHOME"]
        db.set_mediapath("{GRAMPSHOME}/test_var")
        self.assertEqual(media_path(db), os.path.normcase(os.path.normpath(os.path.abspath(USER_HOME + "/test_var"))))

        # Test with $GRAMPSHOME environment variable set
        os.environ["GRAMPSHOME"] = "/this/is/a/test"
        db.set_mediapath("{GRAMPSHOME}/test_var")
        self.assertEqual(
            media_path(db), os.path.normcase(os.path.normpath(os.path.abspath("/this/is/a/test/test_var")))
        )

        #  Restore environment
        os.environ = old_env
コード例 #2
0
ファイル: editreference_test.py プロジェクト: SNoiraud/gramps
 def test_editreference(self):
     dbstate = DbState()
     db = make_database("bsddb")
     path = "/tmp/edit_ref_test"
     try:
         os.mkdir(path)
     except:
         pass
     db.load(path)
     dbstate.change_database(db)
     source = Place()
     source.gramps_id = "P0001"
     dbstate.db.place_map[source.handle] = source.serialize()
     editor = MockEditReference(dbstate, uistate=None, track=[],
                                source=source, source_ref=None, update=None)
     with patch('gramps.gui.editors.editreference.ErrorDialog') as MockED:
         editor.check_for_duplicate_id("Place")
         self.assertTrue(MockED.called)
コード例 #3
0
 def test_editreference(self):
     dbstate = DbState()
     db = dbstate.make_database("bsddb")
     path = "/tmp/edit_ref_test"
     try:
         os.mkdir(path)
     except:
         pass
     db.write_version(path)
     db.load(path)
     dbstate.change_database(db)
     source = Place()
     source.gramps_id = "P0001"
     dbstate.db.place_map[source.handle] = source.serialize()
     editor = MockEditReference(dbstate, uistate=None, track=[],
                                source=source, source_ref=None, update=None)
     with patch('gramps.gui.editors.editreference.ErrorDialog') as MockED:
         editor.check_for_duplicate_id("Place")
         self.assertTrue(MockED.called)
コード例 #4
0
 def test_editreference(self):
     dbstate = DbState()
     db = make_database("sqlite")
     path = "/tmp/edit_ref_test"
     try:
         os.mkdir(path)
     except:
         pass
     db.load(path)
     dbstate.change_database(db)
     source = Place()
     source.gramps_id = "P0001"
     with DbTxn("test place", dbstate.db) as trans:
         dbstate.db.add_place(source, trans)
     editor = MockEditReference(dbstate,
                                uistate=None,
                                track=[],
                                source=source,
                                source_ref=None,
                                update=None)
     with patch('gramps.gui.editors.editreference.ErrorDialog') as MockED:
         editor.check_for_duplicate_id("Place")
         self.assertTrue(MockED.called)
コード例 #5
0
    def test_mediapath(self):
        """
        Test media path variables.
        """

        # Create database
        dbstate = DbState()
        db = dbstate.make_database("bsddb")
        path = get_empty_tempdir("utils_file_test")
        db.write_version(path)
        db.load(path)
        dbstate.change_database(db)

        # Test without db.mediapath set
        self.assertEqual(
            media_path(db),
            os.path.normcase(os.path.normpath(os.path.abspath(USER_HOME))))
        self.assertTrue(os.path.exists(media_path(db)))

        # Test with absolute db.mediapath
        db.set_mediapath(os.path.abspath(USER_HOME) + "/test_abs")
        self.assertEqual(
            media_path(db),
            os.path.normcase(
                os.path.normpath(os.path.abspath(USER_HOME + "/test_abs"))))

        # Test with relative db.mediapath
        db.set_mediapath("test_rel")
        self.assertEqual(
            media_path(db),
            os.path.normcase(
                os.path.normpath(
                    os.path.abspath(TEMP_DIR + "/utils_file_test/test_rel"))))

        # Test with environment variable
        db.set_mediapath("/test/{VERSION}/test_var")
        self.assertEqual(
            media_path(db),
            os.path.normcase(
                os.path.normpath(
                    os.path.abspath("/test/" + VERSION + "/test_var"))))
        db.set_mediapath("{USER_PLUGINS}/test_var")
        self.assertEqual(
            media_path(db),
            os.path.normcase(
                os.path.normpath(os.path.abspath(USER_PLUGINS + "/test_var"))))
        db.set_mediapath("{VERSION}/test_var")
        self.assertEqual(
            media_path(db),
            os.path.normcase(
                os.path.normpath(
                    os.path.abspath(TEMP_DIR + "/utils_file_test/" + VERSION +
                                    "/test_var"))))

        # Test with $GRAMPSHOME environment variable not set
        old_env = os.environ.copy()
        if 'GRAMPSHOME' in os.environ:
            del os.environ['GRAMPSHOME']
        db.set_mediapath("{GRAMPSHOME}/test_var")
        self.assertEqual(
            media_path(db),
            os.path.normcase(
                os.path.normpath(os.path.abspath(USER_HOME + "/test_var"))))

        # Test with $GRAMPSHOME environment variable set
        os.environ['GRAMPSHOME'] = "/this/is/a/test"
        db.set_mediapath("{GRAMPSHOME}/test_var")
        self.assertEqual(
            media_path(db),
            os.path.normcase(
                os.path.normpath(os.path.abspath("/this/is/a/test/test_var"))))

        # Restore environment
        os.environ = old_env