def it_throws_an_error_if_the_sort_order_is_invalid(spark):
     source_df = spark.create_df([
         ("jose", "oak", "switch"),
         ("li", "redwood", "xbox"),
         ("luisa", "maple", "ps4"),
     ], [
         ("name", StringType(), True),
         ("tree", StringType(), True),
         ("gaming_system", StringType(), True),
     ])
     with pytest.raises(ValueError) as excinfo:
         quinn.sort_columns(source_df, "cats")
     assert excinfo.value.args[
         0] == "['asc', 'desc'] are the only valid sort orders and you entered a sort order of 'cats'"
Example #2
0
 def it_sorts_columns_in_desc_order(spark):
     source_df = spark.create_df(
         [
             ("jose", "oak", "switch"),
             ("li", "redwood", "xbox"),
             ("luisa", "maple", "ps4"),
         ],
         [
             ("name", StringType(), True),
             ("tree", StringType(), True),
             ("gaming_system", StringType(), True),
         ],
     )
     actual_df = quinn.sort_columns(source_df, "desc")
     expected_df = spark.create_df(
         [
             ("oak", "jose", "switch"),
             ("redwood", "li", "xbox"),
             ("maple", "luisa", "ps4"),
         ],
         [
             ("tree", StringType(), True),
             ("name", StringType(), True),
             ("gaming_system", StringType(), True),
         ],
     )
     chispa.assert_df_equality(actual_df, expected_df)
Example #3
0
    def test_sort_columns_desc(self):
        source_df = spark.create_df(
            [
                ("jose", "oak", "switch"),
                ("li", "redwood", "xbox"),
                ("luisa", "maple", "ps4"),
            ],
            [
                ("name", StringType(), True),
                ("tree", StringType(), True),
                ("gaming_system", StringType(), True),
            ]
        )

        actual_df = quinn.sort_columns(source_df, "desc")

        expected_df = spark.create_df(
            [
                ("oak", "jose", "switch"),
                ("redwood", "li", "xbox"),
                ("maple", "luisa", "ps4"),
            ],
            [
                ("tree", StringType(), True),
                ("name", StringType(), True),
                ("gaming_system", StringType(), True),
            ]
        )

        assert expected_df.collect() == actual_df.collect()