@@ -53,6 +53,8 @@ def test_exists(self):
5353 def test_not_exists (self ):
5454 doesntexist = os .path .join (self .mkdtemp (), "doesntexist" )
5555 mismatch = PathExists ().match (doesntexist )
56+ self .assertIsNotNone (mismatch )
57+ assert mismatch is not None
5658 self .assertThat (f"{ doesntexist } does not exist." , Equals (mismatch .describe ()))
5759
5860
@@ -63,15 +65,20 @@ def test_exists(self):
6365
6466 def test_not_exists (self ):
6567 doesntexist = os .path .join (self .mkdtemp (), "doesntexist" )
66- mismatch = DirExists ().match (doesntexist )
67- self .assertThat (
68- PathExists ().match (doesntexist ).describe (), Equals (mismatch .describe ())
69- )
68+ dir_mismatch = DirExists ().match (doesntexist )
69+ self .assertIsNotNone (dir_mismatch )
70+ assert dir_mismatch is not None
71+ path_mismatch = PathExists ().match (doesntexist )
72+ self .assertIsNotNone (path_mismatch )
73+ assert path_mismatch is not None
74+ self .assertThat (path_mismatch .describe (), Equals (dir_mismatch .describe ()))
7075
7176 def test_not_a_directory (self ):
7277 filename = os .path .join (self .mkdtemp (), "foo" )
7378 self .touch (filename )
7479 mismatch = DirExists ().match (filename )
80+ self .assertIsNotNone (mismatch )
81+ assert mismatch is not None
7582 self .assertThat (f"{ filename } is not a directory." , Equals (mismatch .describe ()))
7683
7784
@@ -84,14 +91,19 @@ def test_exists(self):
8491
8592 def test_not_exists (self ):
8693 doesntexist = os .path .join (self .mkdtemp (), "doesntexist" )
87- mismatch = FileExists ().match (doesntexist )
88- self .assertThat (
89- PathExists ().match (doesntexist ).describe (), Equals (mismatch .describe ())
90- )
94+ file_mismatch = FileExists ().match (doesntexist )
95+ self .assertIsNotNone (file_mismatch )
96+ assert file_mismatch is not None
97+ path_mismatch = PathExists ().match (doesntexist )
98+ self .assertIsNotNone (path_mismatch )
99+ assert path_mismatch is not None
100+ self .assertThat (path_mismatch .describe (), Equals (file_mismatch .describe ()))
91101
92102 def test_not_a_file (self ):
93103 tempdir = self .mkdtemp ()
94104 mismatch = FileExists ().match (tempdir )
105+ self .assertIsNotNone (mismatch )
106+ assert mismatch is not None
95107 self .assertThat (f"{ tempdir } is not a file." , Equals (mismatch .describe ()))
96108
97109
@@ -102,10 +114,13 @@ def test_empty(self):
102114
103115 def test_not_exists (self ):
104116 doesntexist = os .path .join (self .mkdtemp (), "doesntexist" )
105- mismatch = DirContains ([]).match (doesntexist )
106- self .assertThat (
107- PathExists ().match (doesntexist ).describe (), Equals (mismatch .describe ())
108- )
117+ dir_mismatch = DirContains ([]).match (doesntexist )
118+ self .assertIsNotNone (dir_mismatch )
119+ assert dir_mismatch is not None
120+ path_mismatch = PathExists ().match (doesntexist )
121+ self .assertIsNotNone (path_mismatch )
122+ assert path_mismatch is not None
123+ self .assertThat (path_mismatch .describe (), Equals (dir_mismatch .describe ()))
109124
110125 def test_contains_files (self ):
111126 tempdir = self .mkdtemp ()
@@ -130,20 +145,25 @@ def test_both_specified(self):
130145 def test_does_not_contain_files (self ):
131146 tempdir = self .mkdtemp ()
132147 self .touch (os .path .join (tempdir , "foo" ))
133- mismatch = DirContains (["bar" , "foo" ]).match (tempdir )
134- self .assertThat (
135- Equals (["bar" , "foo" ]).match (["foo" ]).describe (),
136- Equals (mismatch .describe ()),
137- )
148+ mismatch_a = DirContains (["bar" , "foo" ]).match (tempdir )
149+ self .assertIsNotNone (mismatch_a )
150+ assert mismatch_a is not None
151+ mismatch_b = Equals (["bar" , "foo" ]).match (["foo" ])
152+ self .assertIsNotNone (mismatch_b )
153+ assert mismatch_b is not None
154+ self .assertThat (mismatch_b .describe (), Equals (mismatch_a .describe ()))
138155
139156
140157class TestFileContains (TestCase , PathHelpers ):
141158 def test_not_exists (self ):
142159 doesntexist = os .path .join (self .mkdtemp (), "doesntexist" )
143- mismatch = FileContains ("" ).match (doesntexist )
144- self .assertThat (
145- PathExists ().match (doesntexist ).describe (), Equals (mismatch .describe ())
146- )
160+ file_mismatch = FileContains ("" ).match (doesntexist )
161+ self .assertIsNotNone (file_mismatch )
162+ assert file_mismatch is not None
163+ path_mismatch = PathExists ().match (doesntexist )
164+ self .assertIsNotNone (path_mismatch )
165+ assert path_mismatch is not None
166+ self .assertThat (path_mismatch .describe (), Equals (file_mismatch .describe ()))
147167
148168 def test_contains (self ):
149169 tempdir = self .mkdtemp ()
@@ -169,11 +189,13 @@ def test_does_not_contain(self):
169189 tempdir = self .mkdtemp ()
170190 filename = os .path .join (tempdir , "foo" )
171191 self .create_file (filename , "Goodbye Cruel World!" )
172- mismatch = FileContains ("Hello World!" ).match (filename )
173- self .assertThat (
174- Equals ("Hello World!" ).match ("Goodbye Cruel World!" ).describe (),
175- Equals (mismatch .describe ()),
176- )
192+ actual = FileContains ("Hello World!" ).match (filename )
193+ self .assertIsNotNone (actual )
194+ assert actual is not None
195+ expected = Equals ("Hello World!" ).match ("Goodbye Cruel World!" )
196+ self .assertIsNotNone (expected )
197+ assert expected is not None
198+ self .assertThat (expected .describe (), Equals (actual .describe ()))
177199
178200 def test_binary_content (self ):
179201 tempdir = self .mkdtemp ()
@@ -188,11 +210,13 @@ def test_binary_content_mismatch(self):
188210 filename = os .path .join (tempdir , "binary_file" )
189211 with open (filename , "wb" ) as f :
190212 f .write (b"\x00 \x01 \x02 " )
191- mismatch = FileContains (b"\xff \xfe \xfd " ).match (filename )
192- self .assertThat (
193- Equals (b"\xff \xfe \xfd " ).match (b"\x00 \x01 \x02 " ).describe (),
194- Equals (mismatch .describe ()),
195- )
213+ actual = FileContains (b"\xff \xfe \xfd " ).match (filename )
214+ self .assertIsNotNone (actual )
215+ assert actual is not None
216+ expected = Equals (b"\xff \xfe \xfd " ).match (b"\x00 \x01 \x02 " )
217+ self .assertIsNotNone (expected )
218+ assert expected is not None
219+ self .assertThat (expected .describe (), Equals (actual .describe ()))
196220
197221 def test_text_with_encoding (self ):
198222 tempdir = self .mkdtemp ()
@@ -238,10 +262,13 @@ def in_temp_dir(x):
238262 tarball .add (in_temp_dir ("a" ), "a" )
239263 tarball .add (in_temp_dir ("b" ), "b" )
240264 tarball .close ()
241- mismatch = TarballContains (["d" , "c" ]).match (in_temp_dir ("foo.tar.gz" ))
242- self .assertEqual (
243- mismatch .describe (), Equals (["c" , "d" ]).match (["a" , "b" ]).describe ()
244- )
265+ actual = TarballContains (["d" , "c" ]).match (in_temp_dir ("foo.tar.gz" ))
266+ self .assertIsNotNone (actual )
267+ assert actual is not None
268+ expected = Equals (["c" , "d" ]).match (["a" , "b" ])
269+ self .assertIsNotNone (expected )
270+ assert expected is not None
271+ self .assertEqual (actual .describe (), expected .describe ())
245272
246273
247274class TestSamePath (TestCase , PathHelpers ):
0 commit comments