Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Python Testing Be Assertive assertTrue and assertFalse

Elizabeth McInerney
Elizabeth McInerney
3,175 Points

is_palindrome

I am looking for some help to understand what I am missing here.

tests.py
import unittest

from string_fun import is_palindrome


class PalindromeTestCase(unittest.TestCase):
    def test_good_palindrome(self):
        pass

    def test_bad_palindrome(self):
        pass

    def test_is_palindrome(self):
        self.assertTrue(self.is_palindrome == "tacocat")
string_fun.py
def is_palindrome(yarn):
    """Return whether or not a string is a palindrome.

    A palindrome is a word/phrase that's the same in
    both directions.
    """
    return yarn == yarn[::-1]

2 Answers

Kenneth Love
STAFF
Kenneth Love
Treehouse Guest Teacher

You need to actually call is_palindrome (and it doesn't belong to the test instance so you don't use self).

Elizabeth McInerney
Elizabeth McInerney
3,175 Points

Thanks for your help. I understand now. There were 2 things that I did not understand in the video. First was the use of the word dunder a couple of times (the first time at 1:08), when I did not see you type any dunders. (I use CC to watch the videos). The second thing that confused me was not understanding why you used self.rock and self.paper in test_not_equal, but then used self.rock and moves.Rock() in test_equal.

Kenneth Love
Kenneth Love
Treehouse Guest Teacher

"dunder" just means "double underscore" or __. It's pretty common in the Python world, and I think I used it in Object-Oriented Python but I should have explained it here too. Sorry about that.

I didn't use self.rock twice in the second example because I wanted to be sure and have two different Rocks to compare.

Elizabeth McInerney
Elizabeth McInerney
3,175 Points

Yes, I remember what dunder means, I just didn't understand why you were using the term when you weren't adding or looking at any code that had any dunders. So I wasn't sure what part of the code you were referring to. I guess what was also a little confusing about that video was just trying to remember what rock referred to. I know it was from the paper/rock/scissors game, just couldn't remember what it meant for 2 rocks to be equal or not equal. Thanks. I have really enjoyed the course and will hopefully finish soon, just giving user feedback on some things.

Kenneth Love
Kenneth Love
Treehouse Guest Teacher

Oh. If you look in moves.py, you'll see a bunch of dunder methods (magic methods) in the Moves class, which Rock, Paper, and Scissors all extend.

Elizabeth McInerney
Elizabeth McInerney
3,175 Points

I couldn't figure out how to get into the workspace you were showing that included moves.py.

Elizabeth McInerney
Elizabeth McInerney
3,175 Points

This just worked:

class PalindromeTestCase(unittest.TestCase):
    def test_good_palindrome(self):
        self.assertTrue(is_palindrome('tacocat'))
Elizabeth McInerney
Elizabeth McInerney
3,175 Points

The code the worked, will not work without the self.

Kenneth Love
Kenneth Love
Treehouse Guest Teacher

Yes. The assertTrue needs to have self because it comes from TestCase. But is_palindrome doesn't need it because it doesn't belong to TestCase, it is its own stand alone method.

Elizabeth McInerney
Elizabeth McInerney
3,175 Points

How do I get into the Workspace that includes moves.py?

Kenneth Love
Kenneth Love
Treehouse Guest Teacher

It should be attached to all of the videos, down here in the corner:

launch workspace

Is it not there for you?

Elizabeth McInerney
Elizabeth McInerney
3,175 Points

There is a workspace link below the video, but when I click on it, I get a response saying that I need to create a workspace. If I did that, the workspace would be empty.

Kenneth Love
Kenneth Love
Treehouse Guest Teacher

Those are your workspaces that you've already created that are associated with this video. On the bottom right edge of the video player should be the "Launch Workspace" button I screenshotted above. Is it not there?

Elizabeth McInerney
Elizabeth McInerney
3,175 Points

Ok, I just saw it. I had to start running the video to get it to show up. So I launched a workspace, and it contained dice, dungeon and rps, but no moves.

Elizabeth McInerney
Elizabeth McInerney
3,175 Points

I see it now. I may be the only thick student this course gets, but just an FYI that I had trouble knowing where to look for it. ps: the moves Jagger was a good one.