예제 #1
0
def test_pos2cat(json_str_only_index):
    dim = jsonstat.JsonStatDimension("year", 12, 0, None)
    dim.from_string(json_str_only_index)

    assert dim._pos2cat(0).index == "2003"
    assert dim._pos2cat(11).index == "2014"
    assert dim.category(0).index == "2003"
    assert dim.category(0).label is None
예제 #2
0
def test_info_with_label(json_str_size_one):
    dim = jsonstat.JsonStatDimension("concept", 1, 0, None)
    dim.from_string(json_str_size_one)
    expected = ("+-----+------+----------+\n"
                "| pos | idx  | label    |\n"
                "+-----+------+----------+\n"
                "| 0   | 'CA' | 'Canada' |\n"
                "+-----+------+----------+")
    assert expected == dim.__str__()
예제 #3
0
def test_info(json_str_only_index):
    dim = jsonstat.JsonStatDimension("year", 12, 0, None)
    dim.from_string(json_str_only_index)
    expected = ("+-----+--------+-------+\n"
                "| pos | idx    | label |\n"
                "+-----+--------+-------+\n"
                "| 0   | '2003' | ''    |\n"
                "| 1   | '2004' | ''    |\n"
                "| 2   | '2005' | ''    |\n"
                "| 3   | '2006' | ''    |\n"
                "| 4   | '2007' | ''    |\n"
                "| 5   | '2008' | ''    |\n"
                "| 6   | '2009' | ''    |\n"
                "| 7   | '2010' | ''    |\n"
                "| 8   | '2011' | ''    |\n"
                "| 9   | '2012' | ''    |\n"
                "| 10  | '2013' | ''    |\n"
                "| 11  | '2014' | ''    |\n"
                "+-----+--------+-------+")
    assert expected == dim.__str__()
예제 #4
0
def test_exception_not_valid():
    dim = jsonstat.JsonStatDimension("year", 10, 0, None)
    with pytest.raises(jsonstat.JsonStatException):
        dim._idx2pos('2013')
예제 #5
0
def test_getters():
    dim = jsonstat.JsonStatDimension("test_dim", 10, 0, 'role')
    assert dim.did == "test_dim"
    assert len(dim) == 10
    assert dim.pos == 0
    assert dim.role == "role"
예제 #6
0
def test_idx2pos(json_str_only_index):
    dim = jsonstat.JsonStatDimension("year", 12, 0, None)
    dim.from_string(json_str_only_index)
    assert dim._idx2pos("2003") == 0
    assert dim._idx2pos("2014") == 11
예제 #7
0
def test_exception_mismatch_index_and_label(json_str_label_and_index):
    dim = jsonstat.JsonStatDimension("year", 4, 0, None)
    with pytest.raises(jsonstat.JsonStatMalformedJson) as excinfo:
        dim.from_string(json_str_label_and_index)
    expected = "dimension 'year': label 'Canada' is associated with index 'CA' that not exists!"
    assert str(excinfo.value) == expected
예제 #8
0
def test_size_one(json_str_size_one):
    dim = jsonstat.JsonStatDimension("country", 1, 0, None)
    dim.from_string(json_str_size_one)
    assert u'country' == dim.label
    assert 1 == len(dim)
예제 #9
0
def test_exception_hole_in_category_index(json_str_hole_in_index):
    dim = jsonstat.JsonStatDimension("year", 8, 0, None)
    r = re.compile("dimension 'year': index \d+ is greater than size 8")
    with pytest.raises(jsonstat.JsonStatException) as excinfo:
        dim.from_string(json_str_hole_in_index)
    assert r.match(str(excinfo.value))
예제 #10
0
def test_exception_size(json_str_only_index):
    dim = jsonstat.JsonStatDimension("year", 10, 0, None)

    with pytest.raises(jsonstat.JsonStatException):
        dim.from_string(json_str_only_index)