def test_extend(self): self.assertEqual( _.extend({}, { "a": 'b' }).get("a"), 'b', 'can extend an object with the attributes of another') self.assertEqual( _.extend({ "a": 'x' }, { "a": 'b' }).get("a"), 'b', 'properties in source override destination') self.assertEqual( _.extend({ "x": 'x' }, { "a": 'b' }).get("x"), 'x', 'properties not in source dont get overriden') result = _.extend({"x": 'x'}, {"a": 'a'}, {"b": 'b'}) self.assertEqual(result, { "x": 'x', "a": 'a', "b": 'b' }, 'can extend from multiple source objects') result = _.extend({"x": 'x'}, {"a": 'a', "x": 2}, {"a": 'b'}) self.assertEqual( result, { "x": 2, "a": 'b' }, 'extending from multiple source' ' objects last property trumps') result = _.extend({}, {"a": None, "b": None}) self.assertEqual(set(_.keys(result)), {"a", "b"}, 'extend does not copy undefined values')
def test_extend(self): self.assertEqual(_.extend({}, {"a": 'b'}).get("a"), 'b', 'can extend an object with the attributes of another') self.assertEqual(_.extend({"a": 'x'}, {"a": 'b'}).get("a"), 'b', 'properties in source override destination') self.assertEqual(_.extend({"x": 'x'}, {"a": 'b'}).get("x"), 'x', 'properties not in source dont get overriden') result = _.extend({"x": 'x'}, {"a": 'a'}, {"b": 'b'}) self.assertEqual(result, {"x": 'x', "a": 'a', "b": 'b'}, 'can extend from multiple source objects') result = _.extend({"x": 'x'}, {"a": 'a', "x": 2}, {"a": 'b'}) self.assertEqual(result, {"x": 2, "a": 'b'}, 'extending from multiple source objects last property trumps') result = _.extend({}, {"a": None, "b": None}) self.assertEqual(_.keys(result), ["a", "b"], 'extend does not copy undefined values')
def test_keys(self): self.assertEqual(set(_.keys({ "one": 1, "two": 2 })), {'two', 'one'}, 'can extract the keys from an object')
def test_keys(self): self.assertEqual(set(_.keys({"one": 1, "two": 2})), {'two', 'one'}, 'can extract the keys from an object')