예제 #1
0
    def test_multifield_descend_non_dict(self):
        """Test that we can handle non-dicts."""
        formatter = MultiFieldDescend(
            ['city', 'state'],
            StringFormatter())

        self.assertEqual("[1]", formatter.format(1))
예제 #2
0
    def test_multifield_descend(self):
        """Test that we can format dictionaries."""
        formatter = MultiFieldDescend(
            ['city', 'state'],
            NoopFormatter())

        self.assertEqual(
            ["Indy", "IN"],
            formatter.format({"city": "Indy", "state": "IN"}))
예제 #3
0
    def test_multifield_descend_missing_key(self):
        """Test that we can handle missing dictionary keys."""
        formatter = MultiFieldDescend(
            ['city', 'state'],
            NoopFormatter())

        self.assertEqual(
            ["Indy", None],
            formatter.format({"city": "Indy"}))
예제 #4
0
    def test_multifield_descend(self):
        """Test that we can format dictionaries."""
        formatter = MultiFieldDescend(['city', 'state'], NoopFormatter())

        self.assertEqual(["Indy", "IN"],
                         formatter.format({
                             "city": "Indy",
                             "state": "IN"
                         }))
예제 #5
0
 def test_formatting_none(self):
     """Run None through formatters."""
     self.assertEqual("", StringFormatter().format(None))
     self.assertEqual("",
                      JoinFormatter(',', DisallowFormatter()).format(None))
     self.assertEqual("", StrftimeFormatter("%m/%02d/%Y").format(None))
     self.assertEqual([],
                      MultiFieldDescend(['a'],
                                        NoopFormatter()).format(None))
     self.assertEqual(
         '',
         SingleFieldDescend(None, NoopFormatter()).format(None))
예제 #6
0
    def test_multifield_descend_missing_key(self):
        """Test that we can handle missing dictionary keys."""
        formatter = MultiFieldDescend(['city', 'state'], NoopFormatter())

        self.assertEqual(["Indy", None], formatter.format({"city": "Indy"}))
예제 #7
0
    def test_multifield_descend_non_dict(self):
        """Test that we can handle non-dicts."""
        formatter = MultiFieldDescend(['city', 'state'], StringFormatter())

        self.assertEqual("[1]", formatter.format(1))