コード例 #1
0
    def test_filterdict(self):
        d1 = {1: 2, 3: 4, 5: 6, 7: 8}

        DictUtils.assert_dicts_equal(DictUtils.filterdict(d1, {1, 2, 3}), {
            1: 2,
            3: 4
        })
コード例 #2
0
    def test_upperkeys(self):
        td = {six.b("t"): 1, six.text_type("u"): 2, None: 3}

        DictUtils.assert_dicts_equal(DictUtils.upperkeys(td), {
            six.b("T"): 1,
            six.text_type("U"): 2,
            None: 3
        })
コード例 #3
0
ファイル: test_Ranges.py プロジェクト: davidfraser/j5basic
def run_ranges_tst(ranges, expected_tagmap, expected_axislist):
    if isinstance(ranges, list):
        ranges = dict([("tag%d" % n, tagrange) for n, tagrange in enumerate(ranges)])
    tagmap = Ranges.calculateaxes(ranges)
    DictUtils.assert_dicts_equal(tagmap, expected_tagmap)
    axismap = Ranges.tagmaptoaxismap(tagmap)
    axislist = Ranges.sortaxes(axismap)
    assert axislist == expected_axislist
コード例 #4
0
ファイル: test_DictUtils.py プロジェクト: davidfraser/j5basic
    def test_assert_dicts_equal(self):
        d1 = {1:2, 3:4}
        d2 = {1:2, 3:4}
        d3 = {1:3, 3:5}
        d4 = {2:1, 4:3}

        DictUtils.assert_dicts_equal(d1, d2)
        DictUtils.assert_dicts_not_equal(d1, d3)
        DictUtils.assert_dicts_not_equal(d1, d4)
コード例 #5
0
def run_ranges_tst(ranges, expected_tagmap, expected_axislist):
    if isinstance(ranges, list):
        ranges = dict([("tag%d" % n, tagrange)
                       for n, tagrange in enumerate(ranges)])
    tagmap = Ranges.calculateaxes(ranges)
    DictUtils.assert_dicts_equal(tagmap, expected_tagmap)
    axismap = Ranges.tagmaptoaxismap(tagmap)
    axislist = Ranges.sortaxes(axismap)
    assert axislist == expected_axislist
コード例 #6
0
    def test_subtractdicts(self):
        d1 = {1: 2, 3: 4, 5: 6, 7: 8, 9: six.b("10"), 11: six.text_type("12")}
        d2 = {1: 2, 3: 5, 5: "6", 11: six.b("12"), 9: six.text_type("11")}

        DictUtils.assert_dicts_equal(DictUtils.subtractdicts(d1, d2), {
            3: 4,
            5: 6,
            7: 8,
            9: six.b("10")
        })
コード例 #7
0
    def test_merge_dicts(self):
        d1 = {1: 2, 3: 4, 5: 6, 7: 8}
        d2 = {3: 5, 7: 9, 11: 13}

        DictUtils.assert_dicts_equal(DictUtils.merge_dicts(d1, d2), {
            1: 2,
            3: 5,
            5: 6,
            7: 9,
            11: 13
        })
コード例 #8
0
    def test_mapdict(self):
        td = {1: 2, 3: 4, 5: 6}

        def keymap(x):
            return str(x)

        def valuemap(y):
            return y + 1

        DictUtils.assert_dicts_equal(DictUtils.mapdict(td, None, None), td)
        DictUtils.assert_dicts_equal(DictUtils.mapdict(td, keymap, None), {
            "1": 2,
            "3": 4,
            "5": 6
        })
        DictUtils.assert_dicts_equal(DictUtils.mapdict(td, None, valuemap), {
            1: 3,
            3: 5,
            5: 7
        })
        DictUtils.assert_dicts_equal(DictUtils.mapdict(td, keymap, valuemap), {
            "1": 3,
            "3": 5,
            "5": 7
        })
コード例 #9
0
    def test_asset_dicts_equal_naive_datetimes(self):
        d1 = {
            1:
            datetime_tz.datetime_tz(
                2019,
                2,
                8,
                8,
                0,
                0,
                tzinfo=pytz.timezone('Africa/Johannesburg'))
        }
        d2 = {1: datetime_tz.datetime_tz(2019, 2, 8, 6, 0, 0, tzinfo=pytz.utc)}

        DictUtils.assert_dicts_equal(d1, d2, True)
コード例 #10
0
def test_get_or_pop_arg():
    def my_arg_function(foo, bar, jim=3):
        pass

    args = (1, 2)
    kw = {'jim': 3}

    assert Decorators.get_or_pop_arg('bar', args, kw,
                                     inspect.getargspec(my_arg_function)) == 2
    assert args == (1, 2)
    DictUtils.assert_dicts_equal(kw, {'jim': 3})
    assert Decorators.get_or_pop_arg('jim', args, kw,
                                     inspect.getargspec(my_arg_function)) == 3
    assert args == (1, 2)
    DictUtils.assert_dicts_equal(kw, {'jim': 3})

    kw['billybob'] = 4
    assert Decorators.get_or_pop_arg('billybob', args, kw,
                                     inspect.getargspec(my_arg_function)) == 4
    assert args == (1, 2)
    DictUtils.assert_dicts_equal(kw, {'jim': 3})
コード例 #11
0
def test_get_right_args():
    def my_arg_function(foo, bar, jim=3):
        pass

    rightargs = Decorators.getrightargs(my_arg_function, {
        'foo': 1,
        'bar': 2,
        'bob': 3,
        'mary': 4,
        'jim': 5
    })
    DictUtils.assert_dicts_equal(rightargs, {'foo': 1, 'bar': 2, 'jim': 5})
    rightargs = Decorators.getrightargs(my_arg_function, {
        'foo': 1,
        'bar': 2,
        'bob': 3,
        'mary': 4
    })
    DictUtils.assert_dicts_equal(rightargs, {'foo': 1, 'bar': 2})

    class my_arg_class(object):
        def __init__(self, foo, filip):
            pass

    rightargs = Decorators.getrightargs(my_arg_class, {
        'foo': 1,
        'bar': 2,
        'bob': 3,
        'mary': 4
    })
    DictUtils.assert_dicts_equal(rightargs, {'foo': 1, 'filip': None})

    rightargs, rightkw = Decorators.conform_to_argspec((1, 2), {
        'billybob': 5,
        'jim': 3
    }, inspect.getargspec(my_arg_function))
    assert rightargs == [1, 2, 3]
    assert not rightkw