Ejemplo n.º 1
0
 def testEvaluate(self):
     list_columns_command = StatListColumns()
     arg = list_columns_command.argumentTypes()[0]
     file_path = os.path.join(package_directory, 'test_data', 'data.csv')
     data = pd.read_csv(file_path)
     data_object = DataObject(data, ['random', 'dataset'])
     user_conv = DataObject('list categorical columns'.split(' '),
                            ['user', 'conv'])
     arguments = {arg.keyword: data_object, 'user_conv': user_conv}
     result_object = list_columns_command.evaluate(**arguments)
     self.assertEqual(result_object.command_status, CommandStatus.Success)
     # Try false data
     data_object.data = [1, 2, 3]
     result_object = list_columns_command.evaluate(**arguments)
     self.assertEqual(result_object.command_status, CommandStatus.Error)
Ejemplo n.º 2
0
    def testEvaluate(self):
        image_command = ImageDisplay()
        arg = image_command.argumentTypes()[0]
        # Use None when varstore does not have anything stored
        arguments = {arg.keyword: None}
        result_object = image_command.evaluate(**arguments)
        self.assertEqual(result_object.command_status, CommandStatus.Error)

        # Use false data
        data_object = DataObject(123, ['random', 'image'])
        arguments = {arg.keyword: data_object}
        data_object.data = 123
        result_object = image_command.evaluate(**arguments)
        self.assertEqual(result_object.command_status, CommandStatus.Error)
        # No more optional image should be passed by parser:
        result_object = image_command.evaluate(**{arg.keyword: None})
        self.assertEqual(result_object.command_status, CommandStatus.Error)
        # Use real image
        image_data = imread(os.path.join(
            package_directory, 'test_data', 'image.jpg'))
        data_object.data = image_data
        result_object = image_command.evaluate(**arguments)
        self.assertEqual(result_object.command_status, CommandStatus.Success)
        plt.close()
Ejemplo n.º 3
0
 def testTopN(self):
     filter_top = FilterTopN()
     array_data = DataObject(np.array(
         [1, 1, 1, 2, 2, 2, 2, 3, 3, 4, 5, np.nan]),
                             keyword_list=['array'])
     user_conv = 'Find top 2 values in array'
     user_conv = user_conv.lower()
     target = DataObject(user_conv.split(' '), ['user', 'conversation'])
     arguments = {'array_data': array_data, 'target': target}
     result_object = filter_top.evaluate(**arguments)
     self.assertEqual(result_object.command_status, CommandStatus.Success)
     self.assertEqual(result_object.data[-2], True)
     self.assertEqual(result_object.data[-3], True)
     self.assertEqual(result_object.data[-1], False)
     array_data.data = np.array(
         ['Hello', 'how', 'are', 'you', 'how', 'are'])
     result_object = filter_top.evaluate(**arguments)
     self.assertEqual(result_object.command_status, CommandStatus.Success)
     self.assertEqual(result_object.data[0], False)
     self.assertEqual(result_object.data[1], True)
     self.assertEqual(result_object.data[-1], True)
Ejemplo n.º 4
0
    def testEvaluate(self):
        load_command = Load()
        arg = load_command.argumentTypes()[0]
        file_name_data_object = FileObject('', DataType.file_name, '', False)
        file_name_object = DataObject(file_name_data_object,
                                      ['random', 'file'])
        arguments = {arg.keyword: file_name_object}
        pre_eval_res = load_command.preEvaluate(**arguments)
        arguments['pre_evaluate_results'] = pre_eval_res
        result_object = load_command.evaluate(**arguments)
        self.assertEqual(result_object.command_status, CommandStatus.Error)
        file_name_data_object.path = os.path.join(package_directory,
                                                  'test_data', 'data.csv')
        file_name_data_object.data_type = DataType.csv
        file_name_object.data = file_name_data_object
        arguments.pop('pre_evaluate_results', None)

        pre_eval_res = load_command.preEvaluate(**arguments)
        arguments['pre_evaluate_results'] = pre_eval_res
        result_objects = load_command.evaluate(**arguments)
        self.assertEqual(result_objects[0].command_status,
                         CommandStatus.Success)