Пример #1
0
 def test_combine_present_value_extends_list(self):
     """When both dictionaries define a list, the combined value
     is a combined list.
     """
     a_is_true = dict(a=[True])
     a_is_false = dict(a=[False])
     eq_(dict(a=[True, False]), OPDSImporter.combine(a_is_true, a_is_false))
Пример #2
0
    def test_combine(self):
        """An overall test that duplicates a lot of functionality
        in the more specific tests.
        """
        d1 = dict(a_list=[1],
                  a_scalar="old value",
                  a_dict=dict(key1=None, key2=[2], key3="value3"))

        d2 = dict(a_list=[2],
                  a_scalar="new value",
                  a_dict=dict(key1="finally a value",
                              key4="value4",
                              key2=[200]))

        combined = OPDSImporter.combine(d1, d2)

        # Dictionaries get combined recursively.
        d = combined['a_dict']

        # Normal scalar values can be overridden once set.
        eq_("new value", combined['a_scalar'])

        # Missing values are filled in.
        eq_('finally a value', d["key1"])
        eq_('value3', d['key3'])
        eq_('value4', d['key4'])

        # Lists get extended.
        eq_([1, 2], combined['a_list'])
        eq_([2, 200], d['key2'])
Пример #3
0
 def test_combine_present_value_extends_dictionary(self):
     """When both dictionaries define a dictionary, the combined value is
     the result of combining the two dictionaries with a recursive
     combine() call.
     """
     a_is_true = dict(a=dict(b=[True]))
     a_is_false = dict(a=dict(b=[False]))
     eq_(dict(a=dict(b=[True, False])),
         OPDSImporter.combine(a_is_true, a_is_false))
Пример #4
0
 def test_combine_present_value_not_replaced_with_none(self):
     """When combining a dictionary where a key is set to None
     with a dictionary where that key is present, the value
     is left alone.
     """
     a_is_present = dict(a=True)
     a_is_none = dict(a=None, b=True)
     expect = dict(a=True, b=True)
     eq_(expect, OPDSImporter.combine(a_is_present, a_is_none))