当前位置: 首页>>代码示例>>Python>>正文


Python RootTask.write_in_database方法代码示例

本文整理汇总了Python中hqc_meas.tasks.api.RootTask.write_in_database方法的典型用法代码示例。如果您正苦于以下问题:Python RootTask.write_in_database方法的具体用法?Python RootTask.write_in_database怎么用?Python RootTask.write_in_database使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在hqc_meas.tasks.api.RootTask的用法示例。


在下文中一共展示了RootTask.write_in_database方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: TestAWGTransferInterface

# 需要导入模块: from hqc_meas.tasks.api import RootTask [as 别名]
# 或者: from hqc_meas.tasks.api.RootTask import write_in_database [as 别名]
class TestAWGTransferInterface(object):

    def setup(self):
        self.root = RootTask(should_stop=Event(), should_pause=Event())
        self.task = TransferPulseSequenceTask(task_name='Test')
        self.root.children_task.append(self.task)
        self.root.run_time['drivers'] = {'AWG5014B': InstrHelper}
        self.root.write_in_database('int', 2)

        self.sequence = RootSequence()
        self.context = AWGContext()
        self.sequence.context = self.context
        self.sequence.external_vars = {'a': None}
        pulse1 = Pulse(def_1='1.0', def_2='{a}', channel='Ch1_M1')
        pulse2 = Pulse(def_1='{a} + 1.0', def_2='4.0', channel='Ch1_M1')
        pulse3 = Pulse(def_1='{2_stop} + 0.5', def_2='10', channel='Ch1_M1')
        self.sequence.items.extend([pulse1, pulse2, pulse3])

        self.task.sequence = self.sequence
        self.task.sequence_vars = {'a': '{Root_int}'}

        interface = AWGTransferInterface(task=self.task)
        self.task.interface = interface

        self.task.selected_driver = 'AWG5014B'
        self.task.selected_profile = 'Test1'

        def get_ch(s, ch):
            return InstrHelper(({'output_state': 'OFF'},
                                {'select_sequence': lambda s, se: None}))
        prof = ({'owner': [None], 'defined_channels': ('Ch1',)},
                {'get_channel': get_ch, 'to_send': lambda s, se: None})
        self.root.run_time['profiles'] = {'Test1': prof}

    def test_perform(self):
        self.task.perform()
开发者ID:PhilipVinc,项目名称:HQCMeas,代码行数:38,代码来源:test_transfer_pulse_sequence_task.py

示例2: TestSaveTask

# 需要导入模块: from hqc_meas.tasks.api import RootTask [as 别名]
# 或者: from hqc_meas.tasks.api.RootTask import write_in_database [as 别名]
class TestSaveTask(object):

    test_dir = TEST_PATH

    @classmethod
    def setup_class(cls):
        print complete_line(__name__ +
                            ':{}.setup_class()'.format(cls.__name__), '-', 77)
        os.mkdir(cls.test_dir)

    @classmethod
    def teardown_class(cls):
        print complete_line(__name__ +
                            ':{}.teardown_class()'.format(cls.__name__), '-',
                            77)
        # Removing pref files creating during tests.
        try:
            shutil.rmtree(cls.test_dir)

        # Hack for win32.
        except OSError:
            print 'OSError'
            dirs = os.listdir(cls.test_dir)
            for directory in dirs:
                shutil.rmtree(os.path.join(cls.test_dir), directory)
            shutil.rmtree(cls.test_dir)

    def setup(self):
        self.root = RootTask(should_stop=Event(), should_pause=Event())
        self.task = SaveTask(task_name='Test')
        self.root.children_task.append(self.task)

        self.root.write_in_database('int', 1)
        self.root.write_in_database('float', 2.0)
        self.root.write_in_database('str', 'a')

    def teardown(self):
        folder = self.test_dir
        for the_file in os.listdir(folder):
            file_path = os.path.join(folder, the_file)
            if os.path.isfile(file_path):
                os.remove(file_path)

    def test_saving_target_observer(self):
        self.task.saving_target = 'Array'

        assert_equal(self.task.get_from_database('Test_array'),
                     np.array([1.0]))

        self.task.saving_target = 'File'

        aux = self.task.accessible_database_entries()
        assert_not_in('Test_array', aux)

        self.task.saving_target = 'File and array'

        assert_equal(self.task.get_from_database('Test_array'),
                     np.array([1.0]))

    def test_check1(self):
        # Test everything ok in file mode (no array size).
        task = self.task
        task.saving_target = 'File'
        task.folder = self.test_dir
        task.filename = 'test{Root_int}.txt'
        task.file_mode = 'New'
        task.header = 'test'
        task.saved_values = [('toto', '{Root_str}'), ('tata', '{Root_float}')]
        file_path = os.path.join(self.test_dir, 'test1.txt')

        test, traceback = task.check()
        assert_true(test)
        assert_false(traceback)
        assert_false(os.path.isfile(file_path))
        assert_false(task.initialized)

        task.file_mode = 'Add'

        test, traceback = task.check()
        assert_true(test)
        assert_false(traceback)
        assert_true(os.path.isfile(file_path))
        os.remove(file_path)

    def test_check2(self):
        # Test everything of in array mode (assert database state).
        task = self.task
        task.saving_target = 'Array'
        task.array_size = '1000*{Root_float}'
        task.saved_values = [('toto', '{Root_str}'), ('tata', '{Root_float}')]

        test, traceback = task.check()
        assert_true(test)
        assert_false(traceback)
        array = task.get_from_database('Test_array')
        assert_equal(array.dtype.names, ('toto', 'tata'))

    def test_check3(self):
        # Test everything is ok in file & array mode.
        task = self.task
#.........这里部分代码省略.........
开发者ID:jf---,项目名称:HQCMeas,代码行数:103,代码来源:test_save_tasks.py

示例3: TestSaveArrayTask

# 需要导入模块: from hqc_meas.tasks.api import RootTask [as 别名]
# 或者: from hqc_meas.tasks.api.RootTask import write_in_database [as 别名]
class TestSaveArrayTask(object):

    test_dir = TEST_PATH

    @classmethod
    def setup_class(cls):
        print complete_line(__name__ +
                            ':{}.setup_class()'.format(cls.__name__), '-', 77)
        os.mkdir(cls.test_dir)

    @classmethod
    def teardown_class(cls):
        print complete_line(__name__ +
                            ':{}.teardown_class()'.format(cls.__name__), '-',
                            77)
        # Removing pref files creating during tests.
        try:
            shutil.rmtree(cls.test_dir)

        # Hack for win32.
        except OSError:
            print 'OSError'
            dirs = os.listdir(cls.test_dir)
            for directory in dirs:
                shutil.rmtree(os.path.join(cls.test_dir), directory)
            shutil.rmtree(cls.test_dir)

    def setup(self):
        self.root = RootTask(should_stop=Event(), should_pause=Event())
        self.task = SaveArrayTask(task_name='Test')
        self.root.children_task.append(self.task)

        array = np.empty(2, dtype=np.dtype([('a', 'f8'), ('b', 'f8')]))
        array[0] = (0, 1)
        array[1] = (2, 3)
        self.root.write_in_database('array', array)
        self.root.write_in_database('float', 2.0)
        self.root.write_in_database('str', 'a')

    def teardown(self):
        folder = self.test_dir
        for the_file in os.listdir(folder):
            file_path = os.path.join(folder, the_file)
            if os.path.isfile(file_path):
                os.remove(file_path)

    def test_check1(self):
        # Check everything ok in Text mode.
        task = self.task
        task.folder = self.test_dir
        task.filename = 'test_perform{Root_str}.txt'
        task.mode = 'Text file'
        task.header = 'teststs'
        task.target_array = '{Root_array}'

        test, traceback = task.check()

        assert_true(test)
        assert_false(traceback)
        assert_false(os.path.isfile(os.path.join(self.test_dir,
                                                 'test_performa.txt')))

    def test_check2(self):
        # Check everything ok in Binary mode (wrong file extension, and header)
        task = self.task
        task.folder = self.test_dir
        task.filename = 'test_perform{Root_str}.txt'
        task.mode = 'Binary file'
        task.header = 'teststs'
        task.target_array = '{Root_array}'

        test, traceback = task.check()

        assert_true(test)
        assert_equal(len(traceback), 2)
        assert_in('root/Test-header', traceback)
        assert_in('root/Test-file_ext', traceback)
        assert_false(os.path.isfile(os.path.join(self.test_dir,
                                                 'test_performa.npy')))

    def test_check3(self):
        # Check handling a wrong folder.
        task = self.task
        task.folder = self.test_dir + '{eee}'

        test, traceback = task.check()

        assert_false(test)
        assert_equal(len(traceback), 1)

    def test_check4(self):
        # Check handling a wrong filename.
        task = self.task
        task.folder = self.test_dir
        task.filename = '{rr}'

        test, traceback = task.check()

        assert_false(test)
        assert_equal(len(traceback), 1)
#.........这里部分代码省略.........
开发者ID:jf---,项目名称:HQCMeas,代码行数:103,代码来源:test_save_tasks.py

示例4: TestTransferPulseSequenceTask

# 需要导入模块: from hqc_meas.tasks.api import RootTask [as 别名]
# 或者: from hqc_meas.tasks.api.RootTask import write_in_database [as 别名]
class TestTransferPulseSequenceTask(object):

    def setup(self):
        self.root = RootTask(should_stop=Event(), should_pause=Event())
        self.task = TransferPulseSequenceTask(task_name='Test')
        self.root.children_task.append(self.task)
        self.root.run_time['drivers'] = {'AWG5014B': InstrHelper}
        self.root.write_in_database('int', 2)

        self.sequence = RootSequence()
        self.context = AWGContext()
        self.sequence.context = self.context
        self.sequence.external_vars = {'a': None}
        pulse1 = Pulse(def_1='1.0', def_2='{a}', channel='Ch1_M1')
        pulse2 = Pulse(def_1='{a} + 1.0', def_2='4.0', channel='Ch1_M1')
        pulse3 = Pulse(def_1='{2_stop} + 0.5', def_2='10', channel='Ch1_M1')
        self.sequence.items.extend([pulse1, pulse2, pulse3])

        self.task.sequence = self.sequence
        self.task.sequence_vars = {'a': '{Root_int}'}

        interface = AWGTransferInterface(task=self.task)
        self.task.interface = interface

        self.task.selected_driver = 'AWG5014B'
        self.task.selected_profile = 'Test1'

    def test_check_no_sequence(self):
        self.task.sequence = None
        test, traceback = self.task.check()
        assert_false(test)
        assert_equal(len(traceback), 1)

    def test_check_no_interface(self):
        self.task.interface = None
        test, traceback = self.task.check()
        assert_false(test)
        assert_equal(len(traceback), 2)

    def test_check_errors_in_vars(self):
        self.task.sequence_vars = {'a': '**'}
        test, traceback = self.task.check()
        assert_false(test)
        assert_equal(len(traceback), 1)

    def test_check_compilation_errors(self):
        self.task.sequence.items[0].def_1 = 'b'
        test, traceback = self.task.check()
        assert_false(test)
        assert_equal(len(traceback), 1)

    def test_check_wrong_context(self):
        self.task.sequence.context = None
        test, traceback = self.task.check()
        assert_false(test)
        assert_equal(len(traceback), 1)

    def test_check_ok(self):
        test, traceback = self.task.check()
        assert_true(test)

    def test_register_preferences_seq_path(self):
        self.task.sequence_path = 'toto'
        self.task.register_preferences()
        assert_in('sequence_path', self.task.task_preferences)
        assert_not_in('sequence', self.task.task_preferences)

    def test_register_preferences_seq(self):
        self.task.register_preferences()
        assert_not_in('sequence_path', self.task.task_preferences)
        assert_in('sequence', self.task.task_preferences)
开发者ID:PhilipVinc,项目名称:HQCMeas,代码行数:73,代码来源:test_transfer_pulse_sequence_task.py

示例5: TestArrayExtremaTask

# 需要导入模块: from hqc_meas.tasks.api import RootTask [as 别名]
# 或者: from hqc_meas.tasks.api.RootTask import write_in_database [as 别名]
class TestArrayExtremaTask(object):

    def setup(self):
        self.root = RootTask(should_stop=Event(), should_pause=Event())
        self.task = ArrayExtremaTask(task_name='Test')
        self.root.children_task.append(self.task)
        array = np.zeros((5,), dtype=[('var1', 'f8'), ('var2', 'f8')])
        array['var1'][1] = -1
        array['var1'][3] = 1
        self.root.write_in_database('array', array)

    def test_mode_observation(self):
        # Check database is correctly updated when the mode change.
        self.task.mode = 'Min'

        assert_equal(self.task.get_from_database('Test_min_ind'), 0)
        assert_equal(self.task.get_from_database('Test_min_value'), 1.0)
        aux = self.task.accessible_database_entries()
        assert_not_in('Test_max_ind', aux)
        assert_not_in('Test_max_value', aux)

        self.task.mode = 'Max'

        assert_equal(self.task.get_from_database('Test_max_ind'), 0)
        assert_equal(self.task.get_from_database('Test_max_value'), 2.0)
        aux = self.task.accessible_database_entries()
        assert_not_in('Test_min_ind', aux)
        assert_not_in('Test_min_value', aux)

        self.task.mode = 'Max & min'

        assert_equal(self.task.get_from_database('Test_min_ind'), 0)
        assert_equal(self.task.get_from_database('Test_min_value'), 1.0)
        assert_equal(self.task.get_from_database('Test_max_ind'), 0)
        assert_equal(self.task.get_from_database('Test_max_value'), 2.0)

    def test_check1(self):
        # Simply test that everything is ok if the array exists in the database
        self.root.write_in_database('array', np.zeros((5,)))
        self.task.target_array = '{Root_array}'

        test, traceback = self.task.check()
        assert_true(test)
        assert_false(traceback)

    def test_check2(self):
        # Simply test that everything is ok if the array exists in the database
        # and the column name is ok.
        self.task.target_array = '{Root_array}'
        self.task.column_name = 'var1'

        test, traceback = self.task.check()
        assert_true(test)
        assert_false(traceback)

    def test_check3(self):
        # Test handling a wrong array name.
        self.task.target_array = '*{Root_array}'
        self.task.column_name = 'var3'

        test, traceback = self.task.check()
        assert_false(test)
        assert_equal(len(traceback), 1)
        assert_in('root/Test', traceback)

    def test_check4(self):
        # Test handling an array without names when a name is given.
        self.root.write_in_database('array', np.zeros((5,)))
        self.task.target_array = '{Root_array}'
        self.task.column_name = 'var1'

        test, traceback = self.task.check()
        assert_false(test)
        assert_equal(len(traceback), 1)
        assert_in('root/Test', traceback)

    def test_check5(self):
        # Test handling an array with names when no name is given.
        self.task.target_array = '{Root_array}'

        test, traceback = self.task.check()
        assert_false(test)
        assert_equal(len(traceback), 1)
        assert_in('root/Test', traceback)

    def test_check6(self):
        # Test handling a wrong column name.
        self.task.target_array = '{Root_array}'
        self.task.column_name = 'var3'

        test, traceback = self.task.check()
        assert_true(test)
        assert_equal(len(traceback), 1)
        assert_in('root/Test', traceback)

    def test_check7(self):
        # Test handling a 2d array without names.
        self.task.target_array = '{Root_array}'

        array = np.zeros((5, 5))
#.........这里部分代码省略.........
开发者ID:MatthieuDartiailh,项目名称:HQCMeas,代码行数:103,代码来源:test_array_tasks.py

示例6: TestArrayFindValueTask

# 需要导入模块: from hqc_meas.tasks.api import RootTask [as 别名]
# 或者: from hqc_meas.tasks.api.RootTask import write_in_database [as 别名]
class TestArrayFindValueTask(object):

    def setup(self):
        self.root = RootTask(should_stop=Event(), should_pause=Event())
        self.task = ArrayFindValueTask(task_name='Test')
        self.root.children_task.append(self.task)
        array = np.zeros((5,), dtype=[('var1', 'f8'), ('var2', 'f8')])
        array['var1'][1] = -1.5
        array['var1'][3] = 1.6359
        array['var1'][4] = 1.6359
        self.root.write_in_database('array', array)

    def test_check1(self):
        # Simply test that everything is ok if the array exists in the database
        # and value can be evaluated.
        self.root.write_in_database('array', np.zeros((5,)))
        self.task.target_array = '{Root_array}'
        self.task.value = '1.6359'

        test, traceback = self.task.check()
        assert_true(test)
        assert_false(traceback)

    def test_check2(self):
        # Simply test that everything is ok if the array exists in the database
        # the column name is ok, and value can be evaluated.
        self.task.target_array = '{Root_array}'
        self.task.column_name = 'var1'
        self.task.value = '1.6359'

        test, traceback = self.task.check()
        assert_true(test)
        assert_false(traceback)

    def test_check3(self):
        # Test handling a wrong array name.
        self.task.target_array = '*{Root_array}'
        self.task.column_name = 'var3'
        self.task.value = '1.6359'

        test, traceback = self.task.check()
        assert_false(test)
        assert_equal(len(traceback), 1)
        assert_in('root/Test-array', traceback)

    def test_check4(self):
        # Test handling an array without names when a name is given.
        self.root.write_in_database('array', np.zeros((5,)))
        self.task.target_array = '{Root_array}'
        self.task.column_name = 'var1'
        self.task.value = '1.6359'

        test, traceback = self.task.check()
        assert_false(test)
        assert_equal(len(traceback), 1)
        assert_in('root/Test-column', traceback)

    def test_check5(self):
        # Test handling an array with names when no name is given.
        self.task.target_array = '{Root_array}'
        self.task.value = '1.6359'

        test, traceback = self.task.check()
        assert_false(test)
        assert_equal(len(traceback), 1)
        assert_in('root/Test-column', traceback)

    def test_check6(self):
        # Test handling a wrong column name.
        self.task.target_array = '{Root_array}'
        self.task.column_name = 'var3'
        self.task.value = '1.6359'

        test, traceback = self.task.check()
        assert_true(test)
        assert_equal(len(traceback), 1)
        assert_in('root/Test-column', traceback)

    def test_check7(self):
        # Test handling a wrong value.
        self.task.target_array = '{Root_array}'
        self.task.column_name = 'var1'
        self.task.value = '*1.6359'

        test, traceback = self.task.check()
        assert_false(test)
        assert_equal(len(traceback), 1)
        assert_in('root/Test-value', traceback)

    def test_check8(self):
        # Test handling a 2d array value.
        self.task.target_array = '{Root_array}'
        self.task.value = '1.6359'

        array = np.zeros((5, 5))
        self.root.write_in_database('array', array)

        test, traceback = self.task.check()
        assert_false(test)
        assert_equal(len(traceback), 1)
#.........这里部分代码省略.........
开发者ID:MatthieuDartiailh,项目名称:HQCMeas,代码行数:103,代码来源:test_array_tasks.py

示例7: TestSaveFileTask

# 需要导入模块: from hqc_meas.tasks.api import RootTask [as 别名]
# 或者: from hqc_meas.tasks.api.RootTask import write_in_database [as 别名]
class TestSaveFileTask(object):

    test_dir = TEST_PATH + '2'

    @classmethod
    def setup_class(cls):
        print complete_line(__name__ +
                            ':{}.setup_class()'.format(cls.__name__), '-', 77)
        os.mkdir(cls.test_dir)

    @classmethod
    def teardown_class(cls):
        print complete_line(__name__ +
                            ':{}.teardown_class()'.format(cls.__name__), '-',
                            77)
        # Removing pref files creating during tests.
        try:
            shutil.rmtree(cls.test_dir)

        # Hack for win32.
        except OSError:
            print 'OSError'
            dirs = os.listdir(cls.test_dir)
            for directory in dirs:
                shutil.rmtree(os.path.join(cls.test_dir), directory)
            shutil.rmtree(cls.test_dir)

    def setup(self):
        self.root = RootTask(should_stop=Event(), should_pause=Event())
        self.task = SaveFileTask(task_name='Test')
        self.root.children_task.append(self.task)

        self.root.write_in_database('int', 1)
        self.root.write_in_database('float', 2.0)
        self.root.write_in_database('array', np.array(range(10)))

    def teardown(self):
        folder = self.test_dir
        for the_file in os.listdir(folder):
            file_path = os.path.join(folder, the_file)
            if os.path.isfile(file_path):
                os.remove(file_path)

    def test_check1(self):
        # Test everything ok in file mode (no array size).
        task = self.task
        task.folder = self.test_dir
        task.filename = 'test{Root_int}.txt'
        task.saved_values = [('toto', '{Root_int}'), ('tata', '{Root_float}')]
        file_path = os.path.join(self.test_dir, 'test1.txt')

        test, traceback = task.check()
        assert_true(test)
        assert_false(traceback)
        assert_false(os.path.isfile(file_path))
        assert_false(task.initialized)

    def test_check4(self):
        # Test check issues in file mode : folder.
        task = self.task
        task.folder = self.test_dir + '{tt}'

        test, traceback = task.check()
        assert_false(test)
        assert_true(traceback)
        assert_equal(len(traceback), 1)

    def test_check5(self):
        # Test check issues in file mode : file.
        task = self.task
        task.folder = self.test_dir
        task.filename = 'test{tt}.txt'

        test, traceback = task.check()
        assert_false(test)
        assert_true(traceback)
        assert_equal(len(traceback), 1)

    def test_check6(self):
        # Test check issues in file mode : header formatting.
        task = self.task
        task.folder = self.test_dir
        task.filename = 'test.txt'
        task.header = 'test {*}'

        test, traceback = task.check()
        assert_false(test)
        assert_true(traceback)
        assert_equal(len(traceback), 1)

    def test_check9(self):
        # Test check issues in entries.
        task = self.task
        task.folder = self.test_dir
        self.root.write_in_database('int', 3)
        task.filename = 'test{Root_int}.txt'
        task.saved_values = [('toto', '{Root_int*}'),
                             ('tata', '{Root_float*}')]

        test, traceback = task.check()
#.........这里部分代码省略.........
开发者ID:MatthieuDartiailh,项目名称:HQCMeas,代码行数:103,代码来源:test_save_tasks.py


注:本文中的hqc_meas.tasks.api.RootTask.write_in_database方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。