def testDirSize(self): fake_task_uid = 1234 # Create a directory with some files and sub-directory and check its size. test_dir = resolver._temp_download_dir(self.get_temp_dir(), fake_task_uid) tf_v1.gfile.MakeDirs(test_dir) tf_utils.atomic_write_string_to_file( os.path.join(test_dir, "file1"), "content1", False) tf_utils.atomic_write_string_to_file( os.path.join(test_dir, "file2"), "content2", False) test_sub_dir = os.path.join(test_dir, "sub_dir") tf_v1.gfile.MakeDirs(test_sub_dir) tf_utils.atomic_write_string_to_file( os.path.join(test_sub_dir, "file3"), "content3", False) self.assertEqual(3 * 8, resolver._dir_size(test_dir)) self.assertEqual(8, resolver._dir_size(test_sub_dir)) # Treat the directory as a temporary directory used by a module download by # referring to that directory from the lock file. fake_lock_filename = resolver._lock_filename(self.get_temp_dir()) tf_utils.atomic_write_string_to_file( fake_lock_filename, resolver._lock_file_contents(fake_task_uid), False) self.assertEqual(3 * 8, resolver._locked_tmp_dir_size(fake_lock_filename)) # Check that if temp directory doesn't exist, 0 is returned. tf_v1.gfile.DeleteRecursively(test_dir) self.assertEqual(0, resolver._locked_tmp_dir_size(fake_lock_filename))
def testDirSize(self): fake_task_uid = 1234 # Create a directory with some files and sub-directory and check its size. test_dir = resolver._temp_download_dir(self.get_temp_dir(), fake_task_uid) tf.gfile.MakeDirs(test_dir) tf_utils.atomic_write_string_to_file( os.path.join(test_dir, "file1"), "content1", False) tf_utils.atomic_write_string_to_file( os.path.join(test_dir, "file2"), "content2", False) test_sub_dir = os.path.join(test_dir, "sub_dir") tf.gfile.MakeDirs(test_sub_dir) tf_utils.atomic_write_string_to_file( os.path.join(test_sub_dir, "file3"), "content3", False) self.assertEqual(3 * 8, resolver._dir_size(test_dir)) self.assertEqual(8, resolver._dir_size(test_sub_dir)) # Treat the directory as a temporary directory used by a module download by # referring to that directory from the lock file. fake_lock_filename = resolver._lock_filename(self.get_temp_dir()) tf_utils.atomic_write_string_to_file( fake_lock_filename, resolver._lock_file_contents(fake_task_uid), False) self.assertEqual(3 * 8, resolver._locked_tmp_dir_size(fake_lock_filename)) # Check that if temp directory doesn't exist, 0 is returned. tf.gfile.DeleteRecursively(test_dir) self.assertEqual(0, resolver._locked_tmp_dir_size(fake_lock_filename))