Ejemplo n.º 1
0
    def test_parse_line2(self):
        line = "Chandler, Kerri, (623)-668-9293, pink, 123123121"
        formatter = Formatter()
        formatter.parse_line(line, 1)

        self.assertListEqual([], formatter.entries)
        self.assertListEqual([1], formatter.errors)
Ejemplo n.º 2
0
    def test_parse_line4(self):
        line = "asdfawefawea"
        formatter = Formatter()
        formatter.parse_line(line, 3)

        self.assertListEqual([], formatter.entries)
        self.assertListEqual([3], formatter.errors)
Ejemplo n.º 3
0
    def test_parse_line5(self):
        line = "Chandler, Kerri, (623)-668-9293, pink, 12312"
        formatter = Formatter()
        formatter.parse_line(line, 4)
        expected = Entry("pink", "Kerri", "Chandler", "623-668-9293", "12312")

        self.assertListEqual([expected], formatter.entries)
        self.assertListEqual([], formatter.errors)
Ejemplo n.º 4
0
    def test_parse_line3(self):
        line = "James Murphy, yellow, 83880, 018 154 6474"
        formatter = Formatter()
        formatter.parse_line(line, 2)
        expected = Entry("yellow", "James", "Murphy", "018-154-6474", "83880")

        self.assertListEqual([expected], formatter.entries)
        self.assertListEqual([], formatter.errors)
Ejemplo n.º 5
0
    def test_parse_line1(self):
        line = "Booker T., Washington, 87360, 373 781 7380, yellow"
        formatter = Formatter()
        formatter.parse_line(line, 0)
        expected = Entry("yellow", "Booker T.", "Washington", "373-781-7380", "87360")

        self.assertListEqual([expected], formatter.entries)
        self.assertListEqual([], formatter.errors)
Ejemplo n.º 6
0
    def test_extract(self):
        formatter = Formatter()
        formatter.extract("rolodex_test1.txt")
        with open("result.out") as result:
            actual = result.read()
        with open("expected.out") as expected_result:
            expected = expected_result.read()

        self.assertEqual(expected, actual)
Ejemplo n.º 7
0
    def test_format(self):
        in_data = ["Booker T., Washington, 87360, 373 781 7380, yellow",
                   "Chandler, Kerri, (623)-668-9293, pink, 123123121",
                   "James Murphy, yellow, 83880, 018 154 6474",
                   "asdfawefawea"]
        formatter = Formatter()
        result = json.dumps(formatter.format_rolodex(in_data), sort_keys=True)
        expected = """{"entries": [""" + \
        """{"color": "yellow", "firstname": "James", "lastname": "Murphy", """ + \
        """"phonenumber": "018-154-6474", "zipcode": "83880"}, """ + \
        """{"color": "yellow", "firstname": "Booker T.", "lastname": "Washington", """ + \
        """"phonenumber": "373-781-7380", "zipcode": "87360"}], """ + \
        """"errors": [1, 3]}"""

        self.assertEqual(expected, result)
Ejemplo n.º 8
0
    def test_parse_line6(self):
        line0 = "Booker T., Washington, 87360, 373 781 7380, yellow"
        line1 = "Chandler, Kerri, (623)-668-9293, pink, 123123121"
        line2 = "James Murphy, yellow, 83880, 018 154 6474"
        line3 = "asdfawefawea"
        line4 = "Chandler, Kerri, (623)-668-9293, pink, 12312"

        formatter = Formatter()
        formatter.parse_line(line0, 0)
        formatter.parse_line(line1, 1)
        formatter.parse_line(line2, 2)
        formatter.parse_line(line3, 3)
        formatter.parse_line(line4, 4)

        expected0 = Entry("yellow", "Booker T.", "Washington", "373-781-7380", "87360")
        expected2 = Entry("yellow", "James", "Murphy", "018-154-6474", "83880")
        expected4 = Entry("pink", "Kerri", "Chandler", "623-668-9293", "12312")
        expected = [expected0, expected2, expected4]

        self.assertListEqual(expected, formatter.entries)
        self.assertListEqual([1,3], formatter.errors)
Ejemplo n.º 9
0
    def test_normalize_formatted_phone(self):
        number = "(555)-123-4567"
        expected = "555-123-4567"

        self.assertEqual(expected, Formatter.normalize_formatted_phone(number))
Ejemplo n.º 10
0
    def test_normalize_invalid_name_doesnt_have_two_elts(self):
        invalid = "Jaz"
        expected = ["Jaz"]

        self.assertListEqual(expected, Formatter.normalize_split_name(invalid))
Ejemplo n.º 11
0
    def test_normalize_name3(self):
        name = "Jazmine M James"
        expected = ["Jazmine M", "James"]

        self.assertListEqual(expected, Formatter.normalize_split_name(name))