當前位置: 首頁>>代碼示例>>Python>>正文


Python PhilDB.get_file_path方法代碼示例

本文整理匯總了Python中phildb.database.PhilDB.get_file_path方法的典型用法代碼示例。如果您正苦於以下問題:Python PhilDB.get_file_path方法的具體用法?Python PhilDB.get_file_path怎麽用?Python PhilDB.get_file_path使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在phildb.database.PhilDB的用法示例。


在下文中一共展示了PhilDB.get_file_path方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_log_write

# 需要導入模塊: from phildb.database import PhilDB [as 別名]
# 或者: from phildb.database.PhilDB import get_file_path [as 別名]
    def test_log_write(self):
        db = PhilDB(self.test_tsdb)

        db.add_timeseries('410731')
        db.add_timeseries_instance('410731', 'D', 'Foo', measurand = 'Q', source = 'DATA_SOURCE')
        dates = [datetime(2014,1,1), datetime(2014,1,2), datetime(2014,1,3)]
        db.write('410731', 'D', pd.Series(index = dates, data = [1.0, 2.0, 3.0]), measurand = 'Q', source = 'DATA_SOURCE')

        db.write('410731', 'D', pd.Series(index = dates, data = [1.0, 2.5, 3.0]), measurand = 'Q', source = 'DATA_SOURCE')

        db.write('410731', 'D', pd.Series(index = [datetime(2014,1,4)], data = [4.0]), measurand = 'Q', source = 'DATA_SOURCE')

        results = db.read('410731', 'D')
        self.assertEqual(results.values[0], 1.0)
        self.assertEqual(results.values[1], 2.5)
        self.assertEqual(results.values[2], 3.0)
        self.assertEqual(results.values[3], 4.0)

        with tables.open_file(db.get_file_path('410731', 'D', ftype='hdf5'), 'r') as hdf5_file:
            log_grp = hdf5_file.get_node('/data')

            self.assertEqual(log_grp.log[0][0], 1388534400)
            self.assertEqual(log_grp.log[0][1], 1.0)
            self.assertEqual(log_grp.log[0][2], 0)

            self.assertEqual(log_grp.log[1][0], 1388620800)
            self.assertEqual(log_grp.log[1][1], 2.0)

            self.assertEqual(log_grp.log[2][0], 1388707200)
            self.assertEqual(log_grp.log[2][1], 3.0)

            self.assertEqual(log_grp.log[3][0], 1388620800)
            self.assertEqual(log_grp.log[3][1], 2.5)

            self.assertEqual(log_grp.log[4][0], 1388793600)
            self.assertEqual(log_grp.log[4][1], 4.0)
開發者ID:cc272309126,項目名稱:phildb,代碼行數:38,代碼來源:test_database.py

示例2: DatabaseTest

# 需要導入模塊: from phildb.database import PhilDB [as 別名]
# 或者: from phildb.database.PhilDB import get_file_path [as 別名]
class DatabaseTest(unittest.TestCase):
    def setUp(self):
        self.test_data_dir = os.path.join(os.path.dirname(__file__), 'test_data')
        self.temp_dir = tempfile.mkdtemp()

        self.test_tsdb = os.path.join(tempfile.mkdtemp(), 'tsdb')
        shutil.copytree(os.path.join(os.path.dirname(__file__),
            'test_data',
            'test_tsdb'),
            self.test_tsdb)

        db_name = os.path.join(self.test_data_dir, self.test_tsdb)
        self.db = PhilDB(self.test_tsdb)

    def tearDown(self):
        try:
            shutil.rmtree(self.temp_dir)
        except OSError as e:
            if e.errno != 2: # Code 2: No such file or directory.
                raise

        try:
            shutil.rmtree(self.test_tsdb)
        except OSError as e:
            if e.errno != 2: # Code 2: No such file or directory.
                raise

    def test_tsdb_exists(self):
        db_name = os.path.join(self.test_data_dir, 'this_tsdb_does_not_exist')
        with self.assertRaises(IOError) as context:
            db = PhilDB(db_name)

        self.assertEqual(str(context.exception),
            "PhilDB database doesn't exist ({0})".format(db_name))

    def test_missing_meta_data(self):
        db_name = os.path.join(self.test_data_dir, 'missing_meta_data')
        with self.assertRaises(IOError) as context:
            db = PhilDB(db_name)

        self.assertEqual(str(context.exception),
            "PhilDB database doesn't contain meta-database ({0}{1}{2})".format(db_name, os.path.sep, 'tsdb.sqlite'))

    def test_meta_data(self):
        db_name = os.path.join(self.test_data_dir, 'test_tsdb')
        db = PhilDB(db_name)

        self.assertEqual(db.version(), "0.0.6")

    def test_tsdb_data_dir(self):
        db_name = os.path.join(self.test_data_dir, 'test_tsdb')
        db = PhilDB(db_name)
        self.assertEqual(db._PhilDB__data_dir(), os.path.join(db_name, 'data'))

    @mock.patch('uuid.uuid4', generate_uuid)
    def test_tsdb_get_file_path(self):

        self.db.add_timeseries('xyz')
        self.db.add_timeseries_instance('xyz', 'D', 'xyz', measurand='Q', source='DATA_SOURCE')
        self.assertEqual(self.db.get_file_path('xyz', 'D'),
               os.path.join(
                   self.test_tsdb,
                   'data',
                   '47e4e0b40c044c1d8dc4272acfcd6bb3.tsdb'
                   )
               )

        self.assertEqual(self.db.get_file_path('xyz', 'D', ftype='hdf5'),
               os.path.join(
                   self.test_tsdb,
                   'data',
                   '47e4e0b40c044c1d8dc4272acfcd6bb3.hdf5'
                   )
               )

    def test_add_ts_entry(self):
        create(self.temp_dir)
        db = PhilDB(self.temp_dir)
        db.add_timeseries('410730')

        conn = sqlite3.connect(db._PhilDB__meta_data_db())
        c = conn.cursor()
        c.execute("SELECT * FROM timeseries;")
        pk, primary_id = c.fetchone();

        self.assertEqual(primary_id, '410730')

    def test_add_measurand_entry(self):
        create(self.temp_dir)
        db = PhilDB(self.temp_dir)
        db.add_measurand('P', 'PRECIPITATION', 'Precipitation')

        conn = sqlite3.connect(db._PhilDB__meta_data_db())
        c = conn.cursor()
        c.execute("SELECT * FROM measurand;")
        pk, measurand_short_id, measurand_long_id, measurand_description = c.fetchone();

        self.assertEqual(measurand_short_id, 'P')
        self.assertEqual(measurand_long_id, 'PRECIPITATION')
        self.assertEqual(measurand_description, 'Precipitation')
#.........這裏部分代碼省略.........
開發者ID:cc272309126,項目名稱:phildb,代碼行數:103,代碼來源:test_database.py


注:本文中的phildb.database.PhilDB.get_file_path方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。