File size: 966 Bytes
ba2f5d6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import os

import pandas as pd
import pytest

from .. import data as alt


@pytest.fixture
def sample_data():
    return pd.DataFrame({"x": range(10), "y": range(10)})


def test_disable_max_rows(sample_data):
    with alt.data_transformers.enable("default", max_rows=5):
        # Ensure max rows error is raised.
        with pytest.raises(alt.MaxRowsError):
            alt.data_transformers.get()(sample_data)

        # Ensure that max rows error is properly disabled.
        with alt.data_transformers.disable_max_rows():
            alt.data_transformers.get()(sample_data)

    try:
        with alt.data_transformers.enable("json"):
            # Ensure that there is no TypeError for non-max_rows transformers.
            with alt.data_transformers.disable_max_rows():
                jsonfile = alt.data_transformers.get()(sample_data)
    except TypeError:
        jsonfile = {}
    finally:
        if jsonfile:
            os.remove(jsonfile["url"])