Q: PyTest for tables in Python I am new to Python, and I am trying to write a test function for print_table function. The test fails, and I cannot figure out why. Can anyone please help me?
Here is the error:

AssertionError: assert '\x1b(0lqqqqq...qqqqqqj\x1b(B' == '┌──────────┬...──────────┘\n'

script.py
from terminaltables import SingleTable

TABLE_DATA = (
('Platform', 'Years', 'Notes'),
('Mk5', '2007-2009', 'The Golf Mk5 Variant was\nintroduced in 2007.'),
('MKVI', '2009-2013', 'Might actually be Mk5.'),
)

def print_table(TABLE_DATA):
  table_instance = SingleTable(TABLE_DATA)
  table_instance.justify_columns[2] = 'right'
  return table_instance.table

test_printer.py
from script import print_table

def test_table():
  data = [
     ('Platform', 'Years', 'Notes'),
     ('Mk5', '2007-2009', 'The Golf Mk5 Variant was\nintroduced in 2007.'),
     ('MKVI', '2009-2013', 'Might actually be Mk5.'),
    ]


    assert  print_table(data)== "\n".join([
    "┌──────────┬───────────┬──────────────────────────┐",
    "│ Platform │ Years     │                    Notes │",
    "├──────────┼───────────┼──────────────────────────┤",
    "│ Mk5      │ 2007-2009 │ The Golf Mk5 Variant was │",
    "│          │           │      introduced in 2007. │",
    "│ MKVI     │ 2009-2013 │   Might actually be Mk5. │",
    "└──────────┴───────────┴──────────────────────────┘"
   ])


A: The characters being compared are not actually the same, unfortunately. For simplicity, consider the first character:
from script import print_table


def test_table():
    data = [
     ('Platform', 'Years', 'Notes'),
     ('Mk5', '2007-2009', 'The Golf Mk5 Variant was\nintroduced in 2007.'),
     ('MKVI', '2009-2013', 'Might actually be Mk5.'),
    ]

    test = print_table(data)

    expected = "\n".join([
            "┌──────────┬───────────┬──────────────────────────┐",
            "│ Platform │ Years     │                    Notes │",
            "├──────────┼───────────┼──────────────────────────┤",
            "│ Mk5      │ 2007-2009 │ The Golf Mk5 Variant was │",
            "│          │           │      introduced in 2007. │",
            "│ MKVI     │ 2009-2013 │   Might actually be Mk5. │",
            "└──────────┴───────────┴──────────────────────────┘"
           ])

    assert test[0] == expected[0]


This will give you:
>       assert test[0] == expected[0]
E       AssertionError: assert '\x1b' == '┌'
E         - ┌
E         + 

test_printer.py:23: AssertionError


A: Python does not automatically recognize when you have an 'Enter' character between strings. You need to specify "\n" string. Also, when you break a single line of code into multiple lines, as you have done here, you need to specify a line continuation character '' at the end of the line.
Try with this revised function definition:
def test_table():
data = [ \
 ('Platform', 'Years', 'Notes'), \
 ('Mk5', '2007-2009', 'The Golf Mk5 Variant was\nintroduced in 2007.'), \
 ('MKVI', '2009-2013', 'Might actually be Mk5.'), \
]


assert  print_table(data)== "\n".join([        
"┌──────────┬───────────┬──────────────────────────┐\n", \
"│ Platform │ Years     │                    Notes │\n", \
"├──────────┼───────────┼──────────────────────────┤\n", \
"│ Mk5      │ 2007-2009 │ The Golf Mk5 Variant was │\n", \
"│          │           │      introduced in 2007. │\n", \
"│ MKVI     │ 2009-2013 │   Might actually be Mk5. │\n", \
"└──────────┴───────────┴──────────────────────────┘\n"  \

])
