Tisbury Treasure Hunt Task 5 clean_up Report format is confusing

Hi Everybody:

My name is Moises and I just joined this wonderful community.

I have a problem with task 5 on Tisbury Treasure Hunt excercise.

In the instructions section it shows the report format as:

“”"
(‘Brass Spyglass’, ‘Abandoned Lighthouse’, (‘4’, ‘B’), ‘Blue’)\n

But after running my code with no success the results_data shows:

"""('Scrimshawed Whale Tooth', 'Deserted Docks', ('2', 'A'), 'Blue')\n\

My confusion comes from :
- At the beggining of the report, a new line after """ should be included?
- Each line should include the '\n' 

I have tried many alternatives with no success on passing the test. 

Any help to point me to the correct answer is very appreciated.  Thank you very much in advance. Best Regards

Here is my code:

def clean_up(combined_record_group):

    report = '"""'
    for item in combined_record_group:
        list_from_tuple = list(item)
        del list_from_tuple[1]
        new_tuple = tuple(list_from_tuple)
        report += str(new_tuple)
        report += '\n'
    report = report + '"""'
    return report


CODE RUN

        input_data = (
                ('Scrimshawed Whale Tooth', '2A', 'Deserted Docks', ('2', 'A'), 'Blue'),
                ('Brass Spyglass', '4B', 'Abandoned Lighthouse', ('4', 'B'), 'Blue'),
                ('Robot Parrot', '1C', 'Seaside Cottages', ('1', 'C'), 'Blue'),
                ('Glass Starfish', '6D', 'Tangled Seaweed Patch', ('6', 'D'), 'Orange'),
                ('Vintage Pirate Hat', '7E', 'Quiet Inlet (Island of Mystery)', ('7', 'E'), 'Orange'),
                ('Pirate Flag', '7F', 'Windswept Hilltop (Island of Mystery)', ('7', 'F'), 'Orange'),
                ('Crystal Crab', '6A', 'Old Schooner', ('6', 'A'), 'Purple'),
                ('Model Ship in Large Bottle', '8A', 'Harbor Managers Office', ('8', 'A'), 'Purple'),
                ('Angry Monkey Figurine', '5B', 'Stormy Breakwater', ('5', 'B'), 'Purple'),
                ('Carved Wooden Elephant', '8C', 'Foggy Seacave', ('8', 'C'), 'Purple'),
                ('Amethyst  Octopus', '1F', 'Aqua Lagoon (Island of Mystery)', ('1', 'F'), 'Yellow'),
                ('Antique Glass Fishnet Float', '3D', 'Spiky Rocks', ('3', 'D'), 'Yellow'),
                ('Silver Seahorse', '4E', 'Hidden Spring (Island of Mystery)', ('4', 'E'), 'Yellow')
        )

        result_data = """('Scrimshawed Whale Tooth', 'Deserted Docks', ('2', 'A'), 'Blue')\n\
('Brass Spyglass', 'Abandoned Lighthouse', ('4', 'B'), 'Blue')\n\
('Robot Parrot', 'Seaside Cottages', ('1', 'C'), 'Blue')\n\
('Glass Starfish', 'Tangled Seaweed Patch', ('6', 'D'), 'Orange')\n\
('Vintage Pirate Hat', 'Quiet Inlet (Island of Mystery)', ('7', 'E'), 'Orange')\n\
('Pirate Flag', 'Windswept Hilltop (Island of Mystery)', ('7', 'F'), 'Orange')\n\
('Crystal Crab', 'Old Schooner', ('6', 'A'), 'Purple')\n\
('Model Ship in Large Bottle', 'Harbor Managers Office', ('8', 'A'), 'Purple')\n\
('Angry Monkey Figurine', 'Stormy Breakwater', ('5', 'B'), 'Purple')\n\
('Carved Wooden Elephant', 'Foggy Seacave', ('8', 'C'), 'Purple')\n\
('Amethyst  Octopus', 'Aqua Lagoon (Island of Mystery)', ('1', 'F'), 'Yellow')\n\
('Antique Glass Fishnet Float', 'Spiky Rocks', ('3', 'D'), 'Yellow')\n\
('Silver Seahorse', 'Hidden Spring (Island of Mystery)', ('4', 'E'), 'Yellow')\n"""

        self.assertEqual(clean_up(input_data), result_data)
TEST FAILURE
AssertionError: '"""(\'Scrimshawed Whale Tooth\', \'Deser[1012 chars]n"""' != "('Scrimshawed Whale Tooth', 'Deserted Do[876 chars]')\n"
Diff is 1016 characters long. Set self.maxDiff to None to see it.
1 Like

Lines should end with a newline. That is, "\n" … and not "\\n". The output should not start with a newline.

Hi @IsaacG thank you very much for your kind and prompt.

I change my code.

def clean_up(combined_record_group):

report = '"""'
for item in combined_record_group:
    list_from_tuple = list(item)
    del list_from_tuple[1]
    new_tuple = tuple(list_from_tuple)
    report += str(new_tuple)
    report += '\n'
report = report + '"""'
return report

The output that I am receiving from the python console looks like this:

“”“(‘Scrimshawed Whale Tooth’, ‘Deserted Docks’, (‘2’, ‘A’), ‘Blue’)
… continues
(‘Silver Seahorse’, ‘Hidden Spring (Island of Mystery)’, (‘4’, ‘E’), ‘Yellow’)
“””
Still, the test is failing with the following message:

TEST FAILURE

AssertionError: ‘“”“('Scrimshawed Whale Tooth', 'Deser[1012 chars]n”“”’ != “(‘Scrimshawed Whale Tooth’, ‘Deserted Do[876 chars]’)\n” Diff is 1016 characters long. Set self.maxDiff to None to see it.

Once again, thank you very much for your help.

Is ... continues part of the test output? If not, can you paste the full error inside a codeblock? That may make it easier to see the actual diff.

Thank you @IsaacG for your support and patience.

I modified the original post including the full error inside the codeblock.

Can you post the error inside a codeblock? Using codeblocks make text like that much easier to read and to see the diffs.

Sure @IsaacG thanks again for your answer.

This is the full failed message that I am receiving.
Best regards

Blockquote

CODE RUN

        input_data = (
                ('Scrimshawed Whale Tooth', '2A', 'Deserted Docks', ('2', 'A'), 'Blue'),
                ('Brass Spyglass', '4B', 'Abandoned Lighthouse', ('4', 'B'), 'Blue'),
                ('Robot Parrot', '1C', 'Seaside Cottages', ('1', 'C'), 'Blue'),
                ('Glass Starfish', '6D', 'Tangled Seaweed Patch', ('6', 'D'), 'Orange'),
                ('Vintage Pirate Hat', '7E', 'Quiet Inlet (Island of Mystery)', ('7', 'E'), 'Orange'),
                ('Pirate Flag', '7F', 'Windswept Hilltop (Island of Mystery)', ('7', 'F'), 'Orange'),
                ('Crystal Crab', '6A', 'Old Schooner', ('6', 'A'), 'Purple'),
                ('Model Ship in Large Bottle', '8A', 'Harbor Managers Office', ('8', 'A'), 'Purple'),
                ('Angry Monkey Figurine', '5B', 'Stormy Breakwater', ('5', 'B'), 'Purple'),
                ('Carved Wooden Elephant', '8C', 'Foggy Seacave', ('8', 'C'), 'Purple'),
                ('Amethyst  Octopus', '1F', 'Aqua Lagoon (Island of Mystery)', ('1', 'F'), 'Yellow'),
                ('Antique Glass Fishnet Float', '3D', 'Spiky Rocks', ('3', 'D'), 'Yellow'),
                ('Silver Seahorse', '4E', 'Hidden Spring (Island of Mystery)', ('4', 'E'), 'Yellow')
        )

        result_data = """('Scrimshawed Whale Tooth', 'Deserted Docks', ('2', 'A'), 'Blue')\n\
('Brass Spyglass', 'Abandoned Lighthouse', ('4', 'B'), 'Blue')\n\
('Robot Parrot', 'Seaside Cottages', ('1', 'C'), 'Blue')\n\
('Glass Starfish', 'Tangled Seaweed Patch', ('6', 'D'), 'Orange')\n\
('Vintage Pirate Hat', 'Quiet Inlet (Island of Mystery)', ('7', 'E'), 'Orange')\n\
('Pirate Flag', 'Windswept Hilltop (Island of Mystery)', ('7', 'F'), 'Orange')\n\
('Crystal Crab', 'Old Schooner', ('6', 'A'), 'Purple')\n\
('Model Ship in Large Bottle', 'Harbor Managers Office', ('8', 'A'), 'Purple')\n\
('Angry Monkey Figurine', 'Stormy Breakwater', ('5', 'B'), 'Purple')\n\
('Carved Wooden Elephant', 'Foggy Seacave', ('8', 'C'), 'Purple')\n\
('Amethyst  Octopus', 'Aqua Lagoon (Island of Mystery)', ('1', 'F'), 'Yellow')\n\
('Antique Glass Fishnet Float', 'Spiky Rocks', ('3', 'D'), 'Yellow')\n\
('Silver Seahorse', 'Hidden Spring (Island of Mystery)', ('4', 'E'), 'Yellow')\n"""

        self.assertEqual(clean_up(input_data), result_data)

TEST FAILURE

AssertionError: ‘“”“('Scrimshawed Whale Tooth', 'Deser[1012 chars]n”“”’ != “(‘Scrimshawed Whale Tooth’, ‘Deserted Do[876 chars]’)\n” Diff is 1016 characters long. Set self.maxDiff to None to see it.

The diff message is still not codeblocked :frowning:

@moyses It seems that the code you’re pasting is a summarised version (with the [1012 chars] bit). I’m not sure if that’s a copy/paste issue you’re having, the actual output you’re seeing, or something else.

To be clear though, to use codeblocks, you use the there backticks (the characters next to z). Not three double quotes or equivelent.

Just a quick chime-in. For Python, if the diff is over 640 characters, unittest automatically summarizes it.

To see a full diff, the tests have to be run with maxDiff = None, which requires that the test code be altered. I think you can also get a bigger diff by asking Pytest to run with a -vv or -vvv flag (but I can’t remember at the moment).

So for this test case we’d need to add maxDiff in the body of the test class:

class TisburyTreasureTest(unittest.TestCase):
    maxDiff = None

    @pytest.mark.task(taskno=5)
    def test_clean_up(self):
        input_data = (
                ('Scrimshawed Whale Tooth', '2A', 'Deserted Docks', ('2', 'A'), 'Blue'),
                ('Brass Spyglass', '4B', 'Abandoned Lighthouse', ('4', 'B'), 'Blue'),
                ('Robot Parrot', '1C', 'Seaside Cottages', ('1', 'C'), 'Blue'),
                ('Glass Starfish', '6D', 'Tangled Seaweed Patch', ('6', 'D'), 'Orange'),
                ('Vintage Pirate Hat', '7E', 'Quiet Inlet (Island of Mystery)', ('7', 'E'), 'Orange'),
                ('Pirate Flag', '7F', 'Windswept Hilltop (Island of Mystery)', ('7', 'F'), 'Orange'),
                ('Crystal Crab', '6A', 'Old Schooner', ('6', 'A'), 'Purple'),
                ('Model Ship in Large Bottle', '8A', 'Harbor Managers Office', ('8', 'A'), 'Purple'),
                ('Angry Monkey Figurine', '5B', 'Stormy Breakwater', ('5', 'B'), 'Purple'),
                ('Carved Wooden Elephant', '8C', 'Foggy Seacave', ('8', 'C'), 'Purple'),
                ('Amethyst  Octopus', '1F', 'Aqua Lagoon (Island of Mystery)', ('1', 'F'), 'Yellow'),
                ('Antique Glass Fishnet Float', '3D', 'Spiky Rocks', ('3', 'D'), 'Yellow'),
                ('Silver Seahorse', '4E', 'Hidden Spring (Island of Mystery)', ('4', 'E'), 'Yellow')
        )

        result_data = """('Scrimshawed Whale Tooth', 'Deserted Docks', ('2', 'A'), 'Blue')\n\
('Brass Spyglass', 'Abandoned Lighthouse', ('4', 'B'), 'Blue')\n\
('Robot Parrot', 'Seaside Cottages', ('1', 'C'), 'Blue')\n\
('Glass Starfish', 'Tangled Seaweed Patch', ('6', 'D'), 'Orange')\n\
('Vintage Pirate Hat', 'Quiet Inlet (Island of Mystery)', ('7', 'E'), 'Orange')\n\
('Pirate Flag', 'Windswept Hilltop (Island of Mystery)', ('7', 'F'), 'Orange')\n\
('Crystal Crab', 'Old Schooner', ('6', 'A'), 'Purple')\n\
('Model Ship in Large Bottle', 'Harbor Managers Office', ('8', 'A'), 'Purple')\n\
('Angry Monkey Figurine', 'Stormy Breakwater', ('5', 'B'), 'Purple')\n\
('Carved Wooden Elephant', 'Foggy Seacave', ('8', 'C'), 'Purple')\n\
('Amethyst  Octopus', 'Aqua Lagoon (Island of Mystery)', ('1', 'F'), 'Yellow')\n\
('Antique Glass Fishnet Float', 'Spiky Rocks', ('3', 'D'), 'Yellow')\n\
('Silver Seahorse', 'Hidden Spring (Island of Mystery)', ('4', 'E'), 'Yellow')\n"""

        self.assertEqual(clean_up(input_data), result_data, maxdiff=None)

We purposely didn’t want a maxDiff=None for either the Tisbury Treasure Hunt cases or the Cater Waiter ones because of the length of the test data.

However, if the OP can codeblock their full solution (or attach it as a text file), I can run it through the tests locally, and we can see where the problem lies. :smile:

1 Like

@iHiD Thank you very much for your comment. I pasted everything I am receiving in the results tab. Please see the attached image.

Hi @BethanyG Thank you very much for your kind answer. I included the line
maxDiff == None in my code, but that didn’t change the output in the results tab.

Here is the complete code for all the 5 tasks for the Treasure Hunt exercise.

def get_coordinate(record):
    return record[1]


def convert_coordinate(coordinate):
    return tuple(coordinate)


def compare_records(azara_record, rui_record):
    return tuple((azara_record[1])) == rui_record[1]


def create_record(azara_record, rui_record):
    if convert_coordinate(azara_record[1]) == rui_record[1]:
        result = azara_record + rui_record
    else:
        result = 'not a match'
    return result


def clean_up(combined_record_group):
    maxDiff = None
    report = '"""'
    for item in combined_record_group:
        list_from_tuple = list(item)
        del list_from_tuple[1]
        new_tuple = tuple(list_from_tuple)
        report += str(new_tuple)
        report += '\n'
    report = report + '"""'
    return report

Hi @IsaacG . I am pasting the complete message that I am getting at the results tab.

CODE RUN
        input_data = (
                ('Scrimshawed Whale Tooth', '2A', 'Deserted Docks', ('2', 'A'), 'Blue'),
                ('Brass Spyglass', '4B', 'Abandoned Lighthouse', ('4', 'B'), 'Blue'),
                ('Robot Parrot', '1C', 'Seaside Cottages', ('1', 'C'), 'Blue'),
                ('Glass Starfish', '6D', 'Tangled Seaweed Patch', ('6', 'D'), 'Orange'),
                ('Vintage Pirate Hat', '7E', 'Quiet Inlet (Island of Mystery)', ('7', 'E'), 'Orange'),
                ('Pirate Flag', '7F', 'Windswept Hilltop (Island of Mystery)', ('7', 'F'), 'Orange'),
                ('Crystal Crab', '6A', 'Old Schooner', ('6', 'A'), 'Purple'),
                ('Model Ship in Large Bottle', '8A', 'Harbor Managers Office', ('8', 'A'), 'Purple'),
                ('Angry Monkey Figurine', '5B', 'Stormy Breakwater', ('5', 'B'), 'Purple'),
                ('Carved Wooden Elephant', '8C', 'Foggy Seacave', ('8', 'C'), 'Purple'),
                ('Amethyst  Octopus', '1F', 'Aqua Lagoon (Island of Mystery)', ('1', 'F'), 'Yellow'),
                ('Antique Glass Fishnet Float', '3D', 'Spiky Rocks', ('3', 'D'), 'Yellow'),
                ('Silver Seahorse', '4E', 'Hidden Spring (Island of Mystery)', ('4', 'E'), 'Yellow')
        )

        result_data = """('Scrimshawed Whale Tooth', 'Deserted Docks', ('2', 'A'), 'Blue')\n\
('Brass Spyglass', 'Abandoned Lighthouse', ('4', 'B'), 'Blue')\n\
('Robot Parrot', 'Seaside Cottages', ('1', 'C'), 'Blue')\n\
('Glass Starfish', 'Tangled Seaweed Patch', ('6', 'D'), 'Orange')\n\
('Vintage Pirate Hat', 'Quiet Inlet (Island of Mystery)', ('7', 'E'), 'Orange')\n\
('Pirate Flag', 'Windswept Hilltop (Island of Mystery)', ('7', 'F'), 'Orange')\n\
('Crystal Crab', 'Old Schooner', ('6', 'A'), 'Purple')\n\
('Model Ship in Large Bottle', 'Harbor Managers Office', ('8', 'A'), 'Purple')\n\
('Angry Monkey Figurine', 'Stormy Breakwater', ('5', 'B'), 'Purple')\n\
('Carved Wooden Elephant', 'Foggy Seacave', ('8', 'C'), 'Purple')\n\
('Amethyst  Octopus', 'Aqua Lagoon (Island of Mystery)', ('1', 'F'), 'Yellow')\n\
('Antique Glass Fishnet Float', 'Spiky Rocks', ('3', 'D'), 'Yellow')\n\
('Silver Seahorse', 'Hidden Spring (Island of Mystery)', ('4', 'E'), 'Yellow')\n"""

        self.assertEqual(clean_up(input_data), result_data)
TEST FAILURE
AssertionError: '"""(\'Scrimshawed Whale Tooth\', \'Deser[1012 chars]n"""' != "('Scrimshawed Whale Tooth', 'Deserted Do[876 chars]')\n"
Diff is 1016 characters long. Set self.maxDiff to None to see it.

Hi @moyses

The maxDiff = None trick only works in the test code file if you are testing locally on your machine. And even then, it is flakey. It won’t work on the website, since the website is running unaltered test files inside a Docker container.

I actually had to use more involved code on my machine, and put this at the top of the test file just under the imports section:

if 'unittest.util' in __import__('sys').modules:
    # Show full diff in self.assertEqual.
    __import__('sys').modules['unittest.util']._MAX_LENGTH = 999999999

That aside, I have now run the tests locally on my machine on your code and this is what I get for the diff part of the error message:

'"""('Scrimshawed Whale Tooth', 'Deserted Docks', ('2', 'A'), 'Blue')\n('Brass Spyglass', 'Abandoned Lighthouse', ('4', 'B'), 'Blue')\n('Robot Parrot', 'Seaside Cottages', ('1', 'C'), 'Blue')\n('Glass Starfish', 'Tangled Seaweed Patch', ('6', 'D'), 'Orange')\n('Vintage Pirate Hat', 'Quiet Inlet (Island of Mystery)', ('7', 'E'), 'Orange')\n('Pirate Flag', 'Windswept Hilltop (Island of Mystery)', ('7', 'F'), 'Orange')\n('Crystal Crab', 'Old Schooner', ('6', 'A'), 'Purple')\n('Model Ship in Large Bottle', 'Harbor Managers Office', ('8', 'A'), 'Purple')\n('Angry Monkey Figurine', 'Stormy Breakwater', ('5', 'B'), 'Purple')\n('Carved Wooden Elephant', 'Foggy Seacave', ('8', 'C'), 'Purple')\n('Amethyst  Octopus', 'Aqua Lagoon (Island of Mystery)', ('1', 'F'), 'Yellow')\n('Antique Glass Fishnet Float', 'Spiky Rocks', ('3', 'D'), 'Yellow')\n('Silver Seahorse', 'Hidden Spring (Island of Mystery)', ('4', 'E'), 'Yellow')\n"""'

does not equal

"('Scrimshawed Whale Tooth', 'Deserted Docks', ('2', 'A'), 'Blue')\n('Brass Spyglass', 'Abandoned Lighthouse', ('4', 'B'), 'Blue')\n('Robot Parrot', 'Seaside Cottages', ('1', 'C'), 'Blue')\n('Glass Starfish', 'Tangled Seaweed Patch', ('6', 'D'), 'Orange')\n('Vintage Pirate Hat', 'Quiet Inlet (Island of Mystery)', ('7', 'E'), 'Orange')\n('Pirate Flag', 'Windswept Hilltop (Island of Mystery)', ('7', 'F'), 'Orange')\n('Crystal Crab', 'Old Schooner', ('6', 'A'), 'Purple')\n('Model Ship in Large Bottle', 'Harbor Managers Office', ('8', 'A'), 'Purple')\n('Angry Monkey Figurine', 'Stormy Breakwater', ('5', 'B'), 'Purple')\n('Carved Wooden Elephant', 'Foggy Seacave', ('8', 'C'), 'Purple')\n('Amethyst  Octopus', 'Aqua Lagoon (Island of Mystery)', ('1', 'F'), 'Yellow')\n('Antique Glass Fishnet Float', 'Spiky Rocks', ('3', 'D'), 'Yellow')\n('Silver Seahorse', 'Hidden Spring (Island of Mystery)', ('4', 'E'), 'Yellow')\n"

Notice anything about that first block? It appears to have '""" at the beginning and end, where the expected result only has " wrapping the report.

So … I suspect your line that reads

report = '"""'

And your line that reads

report = report + '"""'

Probably need to be looked at and changed. :slightly_smiling_face:

1 Like

Your suggestion did it! Thank you very much for your help.

I also would like to thank @IsaacG and @iHiD for supporting me on this new journey that is learning to code. I appreciated it a lot, I will continue working to be able to get better.

I removed any wrapping and now the test was successful.

Maybe be the instructions for this exercise output could be improved. Removing the initial blank line, the triple quoted wrapping and the ending “\n” for each line.

Current expected output according to the instructions tab:


"""
('Brass Spyglass', 'Abandoned Lighthouse', ('4', 'B'), 'Blue')\n
('Vintage Pirate Hat', 'Quiet Inlet (Island of Mystery)', ('7', 'E'), 'Orange')\n
('Crystal Crab', 'Old Schooner', ('6', 'A'), 'Purple')\n
"""

Successful output for this exercise:

('Brass Spyglass', 'Abandoned Lighthouse', ('4', 'B'), 'Blue')
('Vintage Pirate Hat', 'Quiet Inlet (Island of Mystery)', ('7', 'E'), 'Orange')
('Crystal Crab', 'Old Schooner', ('6', 'A'), 'Purple')
2 Likes