Exemple #1
0
    def test_clean_multicolumn_from_other_tab(self):
        tab_output = ProcessResult(pd.DataFrame({"A-from-tab-2": [1, 2]}))
        workflow = Workflow.create_and_init()
        tab = workflow.tabs.first()
        wfm = tab.wf_modules.create(
            order=0,
            slug="step-1",
            last_relevant_delta_id=workflow.last_delta_id)
        wfm.cache_render_result(workflow.last_delta_id, tab_output)

        schema = ParamDType.Dict({
            "tab":
            ParamDType.Tab(),
            "columns":
            ParamDType.Multicolumn(tab_parameter="tab"),
        })
        params = {"tab": tab.slug, "columns": ["A-from-tab-1", "A-from-tab-2"]}
        context = RenderContext(
            workflow.id,
            None,
            TableShape(3, [Column("A-from-tab-1", ColumnType.NUMBER())]),
            {tab.slug: StepResultShape("ok", tab_output.table_shape)},
            params,
        )
        result = clean_value(schema, params, context)
        # result['tab'] is not what we're testing here
        self.assertEqual(result["columns"], ["A-from-tab-2"])
Exemple #2
0
    def test_clean_multicolumn_from_other_tab(self):
        tab_output = ProcessResult(pd.DataFrame({'A-from-tab-2': [1, 2]}))
        workflow = Workflow.create_and_init()
        tab = workflow.tabs.first()
        wfm = tab.wf_modules.create(
            order=0, last_relevant_delta_id=workflow.last_delta_id)
        wfm.cache_render_result(workflow.last_delta_id, tab_output)

        schema = ParamDType.Dict({
            'tab':
            ParamDType.Tab(),
            'columns':
            ParamDType.Multicolumn(tab_parameter='tab'),
        })
        params = {'tab': tab.slug, 'columns': ['A-from-tab-1', 'A-from-tab-2']}
        context = RenderContext(
            workflow.id, None,
            TableShape(3, [
                Column('A-from-tab-1', ColumnType.NUMBER()),
            ]), {
                tab.slug: StepResultShape('ok', tab_output.table_shape),
            }, params)
        result = clean_value(schema, params, context)
        # result['tab'] is not what we're testing here
        self.assertEqual(result['columns'], ['A-from-tab-2'])
 def test_clean_multicolumn_sort_in_table_order(self):
     input_shape = TableShape(3, [
         Column("B", ColumnType.NUMBER()),
         Column("A", ColumnType.NUMBER())
     ])
     result = clean_value(ParamDType.Multicolumn(), ["A", "B"], input_shape)
     self.assertEqual(result, ["B", "A"])
Exemple #4
0
 def test_clean_multicolumn_sort_in_table_order(self):
     input_shape = TableShape(3, [
         Column('B', ColumnType.NUMBER()),
         Column('A', ColumnType.NUMBER()),
     ])
     result = clean_value(ParamDType.Multicolumn(), ['A', 'B'], input_shape)
     self.assertEqual(result, ['B', 'A'])
Exemple #5
0
    def test_clean_multicolumn_prompting_error_convert_to_text(self):
        # TODO make this _automatic_ instead of quick-fix?
        # ... but for now: prompt for a Quick Fix.
        context = RenderContext(
            None,
            None,
            TableShape(
                3,
                [
                    Column("A", ColumnType.NUMBER()),
                    Column("B", ColumnType.DATETIME()),
                    Column("C", ColumnType.TEXT()),
                ],
            ),
            None,
            None,
        )
        with self.assertRaises(PromptingError) as cm:
            schema = ParamDType.Multicolumn(column_types=frozenset({"text"}))
            clean_value(schema, "A,B", context)

        self.assertEqual(
            cm.exception.errors,
            [
                PromptingError.WrongColumnType(["A", "B"], None,
                                               frozenset({"text"}))
            ],
        )
 def test_clean_multicolumn_missing_is_removed(self):
     input_shape = TableShape(3, [
         Column("A", ColumnType.NUMBER()),
         Column("B", ColumnType.NUMBER())
     ])
     result = clean_value(ParamDType.Multicolumn(), ["A", "X", "B"],
                          input_shape)
     self.assertEqual(result, ["A", "B"])
Exemple #7
0
 def test_clean_multicolumn_missing_is_removed(self):
     input_shape = TableShape(3, [
         Column('A', ColumnType.NUMBER()),
         Column('B', ColumnType.NUMBER()),
     ])
     result = clean_value(ParamDType.Multicolumn(), ['A', 'X', 'B'],
                          input_shape)
     self.assertEqual(result, ['A', 'B'])
Exemple #8
0
 def test_clean_multicolumn_sort_in_table_order(self):
     context = RenderContext(
         None, None,
         TableShape(3, [
             Column('B', ColumnType.NUMBER()),
             Column('A', ColumnType.NUMBER()),
         ]), None, None)
     result = clean_value(ParamDType.Multicolumn(), ['A', 'B'], context)
     self.assertEqual(result, ['B', 'A'])
Exemple #9
0
 def test_clean_multicolumn_missing_is_removed(self):
     context = RenderContext(
         None, None,
         TableShape(3, [
             Column('A', ColumnType.NUMBER()),
             Column('B', ColumnType.NUMBER()),
         ]), None, None)
     result = clean_value(ParamDType.Multicolumn(), ['A', 'X', 'B'],
                          context)
     self.assertEqual(result, ['A', 'B'])
Exemple #10
0
 def test_clean_multicolumn_sort_in_table_order(self):
     context = RenderContext(
         None,
         None,
         TableShape(3, [
             Column("B", ColumnType.NUMBER()),
             Column("A", ColumnType.NUMBER())
         ]),
         None,
         None,
     )
     result = clean_value(ParamDType.Multicolumn(), ["A", "B"], context)
     self.assertEqual(result, ["B", "A"])
Exemple #11
0
 def test_clean_multicolumn_missing_is_removed(self):
     context = RenderContext(
         None,
         None,
         TableShape(3, [
             Column("A", ColumnType.NUMBER()),
             Column("B", ColumnType.NUMBER())
         ]),
         None,
         None,
     )
     result = clean_value(ParamDType.Multicolumn(), ["A", "X", "B"],
                          context)
     self.assertEqual(result, ["A", "B"])
Exemple #12
0
    def test_clean_multicolumn_prompting_error_convert_to_text(self):
        # TODO make this _automatic_ instead of quick-fix?
        # ... but for now: prompt for a Quick Fix.
        input_shape = TableShape(3, [
            Column('A', ColumnType.NUMBER()),
            Column('B', ColumnType.DATETIME()),
            Column('C', ColumnType.TEXT()),
        ])
        with self.assertRaises(PromptingError) as cm:
            schema = ParamDType.Multicolumn(column_types=frozenset({'text'}))
            clean_value(schema, 'A,B', input_shape)

        self.assertEqual(cm.exception.errors, [
            PromptingError.WrongColumnType(['A'], 'number', frozenset({'text'
                                                                       })),
            PromptingError.WrongColumnType(['B'], 'datetime',
                                           frozenset({'text'})),
        ])
Exemple #13
0
    def test_clean_multicolumn_from_other_tab_that_does_not_exist(self):
        # The other tab would not exist if the user selected and then deleted
        # it.
        workflow = Workflow.create_and_init()
        workflow.tabs.first()

        schema = ParamDType.Dict({
            'tab': ParamDType.Tab(),
            'columns': ParamDType.Multicolumn(tab_parameter='tab'),
        })
        param_values = {'tab': 'tab-missing', 'columns': ['A-from-tab']}
        params = Params(schema, param_values, {})
        context = RenderContext(workflow.id, None, TableShape(3, [
            Column('A-from-tab-1', ColumnType.NUMBER()),
        ]), {}, params)
        result = clean_value(schema, param_values, context)
        # result['tab'] is not what we're testing here
        self.assertEqual(result['columns'], [])
Exemple #14
0
    def test_clean_multicolumn_from_other_tab_that_does_not_exist(self):
        # The other tab would not exist if the user selected and then deleted
        # it.
        workflow = Workflow.create_and_init()
        workflow.tabs.first()

        schema = ParamDType.Dict({
            "tab":
            ParamDType.Tab(),
            "columns":
            ParamDType.Multicolumn(tab_parameter="tab"),
        })
        params = {"tab": "tab-missing", "columns": ["A-from-tab"]}
        context = RenderContext(
            workflow.id,
            None,
            TableShape(3, [Column("A-from-tab-1", ColumnType.NUMBER())]),
            {},
            params,
        )
        result = clean_value(schema, params, context)
        # result['tab'] is not what we're testing here
        self.assertEqual(result["columns"], [])
 def test_clean_multicolumn_no_input_is_empty(self):
     self.assertEqual(clean_value(ParamDType.Multicolumn(), "A", None), [])