Exemplo n.º 1
0
 def test_clean_column_valid(self):
     context = RenderContext(
         None, TableShape(3, [
             Column('A', ColumnType.NUMBER()),
         ]), None, None)
     result = clean_value(ParamDType.Column(), 'A', context)
     self.assertEqual(result, 'A')
Exemplo n.º 2
0
 def test_clean_column_missing_becomes_empty_string(self):
     context = RenderContext(
         None, TableShape(3, [
             Column('A', ColumnType.NUMBER()),
         ]), None, None)
     result = clean_value(ParamDType.Column(), 'B', context)
     self.assertEqual(result, '')
Exemplo n.º 3
0
    def test_clean_multichartseries_non_number_is_prompting_error(self):
        context = RenderContext(
            None,
            TableShape(3, [
                Column('A', ColumnType.TEXT()),
                Column('B', ColumnType.DATETIME()),
            ]), None, None)
        value = [
            {
                'column': 'A',
                'color': '#aaaaaa'
            },
            {
                'column': 'B',
                'color': '#cccccc'
            },
        ]
        with self.assertRaises(PromptingError) as cm:
            clean_value(ParamDType.Multichartseries(), value, context)

        self.assertEqual(cm.exception.errors, [
            PromptingError.WrongColumnType(['A'], 'text', frozenset({'number'
                                                                     })),
            PromptingError.WrongColumnType(['B'], 'datetime',
                                           frozenset({'number'})),
        ])
Exemplo n.º 4
0
 def test_clean_multicolumn_sort_in_table_order(self):
     context = RenderContext(
         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'])
Exemplo n.º 5
0
 def test_clean_multicolumn_missing_is_removed(self):
     context = RenderContext(
         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'])
Exemplo n.º 6
0
 def test_clean_column_missing_becomes_empty_string(self):
     context = RenderContext(
         None, TableShape(3, [
             Column('A', ColumnType.NUMBER),
         ]), None, None)
     schema = ParamDType.Dict({
         'column': ParamDType.Column(),
     })
     value = {'column': 'B'}
     result = clean_value(schema, value, context)
     self.assertEqual(result, {'column': ''})
Exemplo n.º 7
0
 def test_clean_multicolumn_missing_is_removed(self):
     context = RenderContext(
         None,
         TableShape(3, [
             Column('A', ColumnType.NUMBER),
             Column('B', ColumnType.NUMBER),
         ]), None, None)
     schema = ParamDType.Dict({
         'columns': ParamDType.Multicolumn(),
     })
     value = {'columns': 'A,X,B'}
     result = clean_value(schema, value, context)
     self.assertEqual(result, {'columns': 'A,B'})
Exemplo n.º 8
0
    def test_clean_column_prompting_error_convert_to_text(self):
        # TODO make this _automatic_ instead of quick-fix?
        # Consider Regex. We probably want to pass the module a text Series
        # _separately_ from the input DataFrame. That way Regex can output
        # a new Text column but preserve its input column's data type.
        #
        # ... but for now: prompt for a Quick Fix.
        context = RenderContext(None, None, TableShape(3, [
            Column('A', ColumnType.NUMBER()),
        ]), None, None)
        with self.assertRaises(PromptingError) as cm:
            clean_value(ParamDType.Column(column_types=frozenset({'text'})),
                        'A', context)

        self.assertEqual(cm.exception.errors, [
            PromptingError.WrongColumnType(['A'], 'number',
                                           frozenset({'text'})),
        ])
Exemplo n.º 9
0
    def test_clean_tabs_happy_path(self):
        tab1_output = ProcessResult(pd.DataFrame({'A': [1, 2]}))
        workflow = Workflow.create_and_init()
        tab1 = workflow.tabs.first()
        wfm = tab1.wf_modules.create(
            order=0, last_relevant_delta_id=workflow.last_delta_id)
        wfm.cache_render_result(workflow.last_delta_id, tab1_output)

        context = RenderContext(
            workflow.id, None, {
                tab1.slug: StepResultShape('ok', tab1_output.table_shape),
            }, None)
        result = clean_value(ParamDType.Multitab(), [tab1.slug], context)
        self.assertEqual(result[0].slug, tab1.slug)
        self.assertEqual(result[0].name, tab1.name)
        self.assertEqual(result[0].columns, {
            'A': RenderColumn('A', 'number', '{:,}'),
        })
        assert_frame_equal(result[0].dataframe, pd.DataFrame({'A': [1, 2]}))
Exemplo n.º 10
0
 def test_clean_tabs_tab_error_raises_cycle(self):
     context = RenderContext(None, None, {'tab-1': None}, None)
     schema = ParamDType.Dict({'tabs': ParamDType.Multitab()})
     with self.assertRaises(TabCycleError):
         clean_value(schema, {'tabs': ['tab-1']}, context)