Locked learning resources

Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Locked learning resources

This lesson is for members only. Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Testing Final Code

00:00 To test your final code from validator import Song, maybe start with a Song instance that is correct. So Song, there’s a string that is longer than two characters, and a string that is longer than three characters.

00:17 If I hit Enter now, you can see that .__set__() is being accessed twice, once for ._title, where it then stores "A Forest" and once for ._artist, where it then stores "The Cure".

00:32 See that again? Apply vars().

00:35 And indeed, now you see _title and _artist in the namespace of the Song class instance. So that works. Can we still apply the string to s1?

00:48 Indeed we can. And then .__get__() gets triggered twice, once for _title and once for _artist. And then we get the output we hoped for, this is "A Forest" by "The Cure". So that all works.

01:01 What’s left to check is the validation. So let’s create another song. Let’s test the title

01:10 and keep the artist’s name correct. So this should tell me that indeed “1” should be a string. Press the up arrow and instead of “1”, I’ll have a string.

01:22 But let’s make that a short one. So let’s call that, “A”, should be 2. So it should give me an error that indeed “A” should be a length of 2 or longer.

01:32 Press up arrow. Again, I’m going to get the title correct. So "A Forest", but then create some errors for the artist. So the artist needs to be 3 characters, at least. This is only two.

01:44 So indeed now, it tells me that `”Th” should be of length 3 or longer`.

01:50 And the final thing to check is what if I put in an integer? Something that is not a string indeed, and then tells me that “5” should be a string. So there you have it.

02:01 You now have a fully functioning descriptor. Congratulations. And not only do you have a descriptor that works, you have one that is very flexible in the sense that it takes input parameters, and it creates the private names based on the class attributes to which the instance of the descriptor class is being assigned.

Become a Member to join the conversation.