How to use _get_stat_result method in autotest

Best Python code snippet using autotest_python

source_unittest.py

Source:source_unittest.py Github

copy

Full Screen

...250 super(directory_source_unittest, self).setUp()251 self.god.stub_function(os, 'listdir')252 self._stat_mock = self.god.create_mock_function('stat')253 @staticmethod254 def _get_stat_result(mode=0644, ino=12345, dev=12345, nlink=1, uid=1000,255 gid=1000, size=10, atime=123, mtime=123, ctime=123):256 """257 Build an os.stat_result() instance with many default values.258 :param mode, ino, dev, nlink, uid, gid, size, atime, mtime, ctime:259 See help(os.stat_result).260 """261 return os.stat_result((mode, ino, dev, nlink, uid, gid, size, atime,262 mtime, ctime))263 def test_get_new_files_invalid_path(self):264 """265 Test directory_source.get_new_files() on an invalid path.266 """267 path = '/some/invalid/path'268 os.listdir.expect_call(path).and_raises(OSError('Error'))269 s = source.directory_source(self.db_mock, path)270 self.assertRaises(OSError, s.get_new_files)271 self.god.check_playback()272 def test_get_new_files_stat_fails(self):273 """274 Test directory_source.get_new_files() when stat fails.275 """276 path = '/some/valid/path'277 os.listdir.expect_call(path).and_return(['file1', 'file2'])278 (self._stat_mock.expect_call(os.path.join(path, 'file1'))279 .and_raises(OSError('Error')))280 stat_result = self._get_stat_result(size=1010, mtime=123)281 file2_full_path = os.path.join(path, 'file2')282 self._stat_mock.expect_call(file2_full_path).and_return(stat_result)283 self.db_mock.get_dictionary.expect_call().and_return({})284 s = source.directory_source(self.db_mock, path)285 expected = {'file2': source.database.item(file2_full_path, 1010, 123)}286 self.assertEquals(expected, s.get_new_files(_stat_func=self._stat_mock))287 self.god.check_playback()288 def test_get_new_files_success(self):289 """290 Test directory_source.get_new_files() success.291 """292 path = '/some/valid/path'293 file1_full_path = os.path.join(path, 'file1')294 file2_full_path = os.path.join(path, 'file2')295 file3_full_path = os.path.join(path, 'file3')296 os.listdir.expect_call(path).and_return(['file1', 'file2', 'file3'])297 stat_result = self._get_stat_result(size=1010, mtime=123)298 self._stat_mock.expect_call(file1_full_path).and_return(stat_result)299 stat_result = self._get_stat_result(size=1020, mtime=1234)300 self._stat_mock.expect_call(file2_full_path).and_return(stat_result)301 stat_result = self._get_stat_result(size=1030, mtime=12345)302 self._stat_mock.expect_call(file3_full_path).and_return(stat_result)303 known_files = {304 'file2': source.database.item(file2_full_path, 1020, 1234),305 }306 self.db_mock.get_dictionary.expect_call().and_return(known_files)307 s = source.directory_source(self.db_mock, path)308 expected = {309 'file1': source.database.item(file1_full_path, 1010, 123),310 'file3': source.database.item(file3_full_path, 1030, 12345),311 }312 self.assertEquals(expected, s.get_new_files(_stat_func=self._stat_mock))313 self.god.check_playback()314if __name__ == "__main__":315 unittest.main()

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run autotest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful