예제 #1
0
    def test_join(self):
        # Nothing too technical, do not need to test pandas functions
        set_string(self.url_pval, self.valid_workflow_URL)
        set_string(self.colnames_pval, 'key')

        set_integer(self.type_pval, _join_type_map.index("inner"))
        result = JoinURL.render(self.wfm, self.table)
        assert_frame_equal(self.ref_left_join, result.dataframe)
예제 #2
0
    def test_type_mismatch(self):
        # Joining on column with different dtypes should fail
        set_string(self.url_pval, self.valid_workflow_URL)
        set_string(self.colnames_pval, 'key')

        set_integer(self.type_pval, _join_type_map.index("inner"))
        result = JoinURL.render(self.wfm, self.table_with_types)
        self.assertEqual(("Types do not match for key column 'key' (number and text). " \
                        'Please use a type conversion module to make these column types consistent.'), result.error)
예제 #3
0
    def test_type_num_cast(self):
        # Joining on column that is both int and float, module should convert to float
        version = self.wfm.store_fetched_table(self.ext_workflow_with_types)
        self.wfm.set_fetched_data_version(version)
        set_string(self.url_pval, self.valid_workflow_URL)
        set_string(self.colnames_pval, 'key')

        set_integer(self.type_pval, _join_type_map.index("inner"))
        result = JoinURL.render(self.wfm, self.table_with_types)
        assert_frame_equal(self.ref_left_join_with_types, result.dataframe)
    def test_invalid_url(self):
        version = self.wfm.store_fetched_table(self.csv_table)
        self.wfm.set_fetched_data_version(version)

        set_string(self.url_pval, 'not a url')

        result = ConcatURL.render(self.wfm, self.table)
        self.assertTrue('URL' in result.error)

        # Working, non-workflow URL should fail
        set_string(self.url_pval, 'www.google.com')

        result = ConcatURL.render(self.wfm, self.table)
        self.assertTrue('URL' in result.error)
    def test_concat_with_source(self):
        version = self.wfm.store_fetched_table(self.ext_workflow)
        self.wfm.set_fetched_data_version(version)
        set_string(self.url_pval, self.valid_workflow_URL)
        set_checkbox(self.source_columns_pval, True)

        set_integer(self.type_pval, _type_map.index("include columns from both workflows"))
        result = ConcatURL.render(self.wfm, self.table)
        # Sanitize dataframe to clean index created by pandas concat()
        result.sanitize_in_place()

        ref = self.ref_outer_concat.copy()
        ref.insert(0, _source_column_name, ['Current', 'Current', '2', '2'])

        assert_frame_equal(ref, result.dataframe)
    def test_concat(self):
        version = self.wfm.store_fetched_table(self.ext_workflow)
        self.wfm.set_fetched_data_version(version)
        set_string(self.url_pval, self.valid_workflow_URL)
        set_checkbox(self.source_columns_pval, False)

        set_integer(self.type_pval, _type_map.index("only include this workflow's columns"))
        result = ConcatURL.render(self.wfm, self.table)
        # Sanitize dataframe to clean index created by pandas concat()
        result.sanitize_in_place()
        assert_frame_equal(self.ref_source_only_concat, result.dataframe)

        set_integer(self.type_pval, _type_map.index("only include matching columns"))
        result = ConcatURL.render(self.wfm, self.table)
        # Sanitize dataframe to clean index created by pandas concat()
        result.sanitize_in_place()
        assert_frame_equal(self.ref_inner_concat, result.dataframe)

        set_integer(self.type_pval, _type_map.index("include columns from both workflows"))
        result = ConcatURL.render(self.wfm, self.table)
        # Sanitize dataframe to clean index created by pandas concat()
        result.sanitize_in_place()
        assert_frame_equal(self.ref_outer_concat, result.dataframe)
예제 #7
0
    def test_columns_no_exist(self):
        # Should throw error for select column not existing
        set_checkbox(self.select_columns_pval, True)
        set_string(self.importcols_pval, 'non_existent_col')
        set_string(self.colnames_pval, 'key')
        result = JoinURL.render(self.wfm, self.table)
        self.assertEqual(
            "Import columns not in target workflow: {'non_existent_col'}",
            result.error)

        # Should throw error for select column not existing
        set_string(self.importcols_pval, '')
        set_string(self.colnames_pval, 'non_existent_col')
        result = JoinURL.render(self.wfm, self.table)
        self.assertEqual(
            "Key columns not in target workflow: {'non_existent_col'}",
            result.error)
예제 #8
0
    def test_importcols(self):
        # Should only import 1 column
        set_string(self.url_pval, self.valid_workflow_URL)
        set_string(self.colnames_pval, 'key')
        set_string(self.importcols_pval, 'col2')
        set_checkbox(self.select_columns_pval, True)

        set_integer(self.type_pval, _join_type_map.index("inner"))
        result = JoinURL.render(self.wfm, self.table.copy())
        assert_frame_equal(self.ref_left_join[['col1', 'key', 'col2']],
                           result.dataframe)

        # When select_column false, should import all columns
        set_checkbox(self.select_columns_pval, False)
        result = JoinURL.render(self.wfm, self.table.copy())
        assert_frame_equal(self.ref_left_join, result.dataframe)
예제 #9
0
 def test_tsv(self):
     set_string(self.csv_pval, count_tsv)
     result = execute_wfmodule(self.wf_module)
     self.assertEqual(result, ProcessResult(reference_table))
예제 #10
0
 def test_empty(self):
     set_string(self.csv_pval, '')
     result = execute_wfmodule(self.wf_module)
     self.assertEqual(result, ProcessResult(pd.DataFrame()))