WEBVTT 1 00:00:00.240 --> 00:00:02.290 Hi, guys and welcome back. 2 00:00:02.290 --> 00:00:04.990 Next up we're going to be testing classes. 3 00:00:04.990 --> 00:00:06.240 So, we're gonna first of all 4 00:00:06.240 --> 00:00:08.130 create a new Python file 5 00:00:08.130 --> 00:00:10.220 that's gonna be our printer. 6 00:00:10.220 --> 00:00:13.490 And here we're going to create a printer class 7 00:00:13.490 --> 00:00:16.260 that has a simple, in it, method 8 00:00:16.260 --> 00:00:18.870 with the pages per second 9 00:00:18.870 --> 00:00:20.683 and the capacity of the print. 10 00:00:22.120 --> 00:00:24.300 And we're gonna have a simple class here 11 00:00:24.300 --> 00:00:27.553 that just allows to mock a print. 12 00:00:45.400 --> 00:00:47.970 So we've created this simple printer class 13 00:00:47.970 --> 00:00:49.860 and what it does is it takes two values, 14 00:00:49.860 --> 00:00:53.460 how many pages this printer prints in one second 15 00:00:53.460 --> 00:00:56.420 and how many pages it has capacity for. 16 00:00:56.420 --> 00:00:58.830 How much ink it's got left, if you will. 17 00:00:58.830 --> 00:01:00.590 Then there is a print method 18 00:01:00.590 --> 00:01:02.490 that prints a certain number of pages 19 00:01:02.490 --> 00:01:05.010 unless the pages are above the current capacity 20 00:01:05.010 --> 00:01:07.640 in which case, it raises a printer error. 21 00:01:07.640 --> 00:01:09.290 After that, the capacity decreases 22 00:01:09.290 --> 00:01:10.490 by the number of pages printed 23 00:01:10.490 --> 00:01:12.700 and it returns a nice message there 24 00:01:12.700 --> 00:01:14.850 that tells you how many pages were printed. 25 00:01:15.900 --> 00:01:18.600 We've autograted a custom printer error class 26 00:01:18.600 --> 00:01:20.223 that is what is raised here. 27 00:01:21.210 --> 00:01:22.110 Now, let's go ahead 28 00:01:22.110 --> 00:01:25.513 and create a new file called test_printer.py. 29 00:01:28.330 --> 00:01:30.650 And here is where we're gonna be writing our tests 30 00:01:30.650 --> 00:01:32.120 for this printer. 31 00:01:32.120 --> 00:01:34.560 Now, there is a couple of things that we need to look at 32 00:01:34.560 --> 00:01:37.120 when testing a class. 33 00:01:37.120 --> 00:01:39.940 The first thing is that we need to create a class object 34 00:01:39.940 --> 00:01:41.020 so we need to think about 35 00:01:41.020 --> 00:01:43.430 whether we wanna create that on every test 36 00:01:43.430 --> 00:01:45.300 or we wanna create it once 37 00:01:45.300 --> 00:01:47.573 for the entire test case. 38 00:01:48.410 --> 00:01:50.120 We're going to look at how to do that 39 00:01:50.120 --> 00:01:52.600 and also on writing tests for this printer 40 00:01:52.600 --> 00:01:55.267 in the next video, so I'll see you there.