How to use fileSystem method in ts-auto-mock

Best JavaScript code snippet using ts-auto-mock

jquery.filesystem.js

Source:jquery.filesystem.js Github

copy

Full Screen

1/**2 * @author Jerome Morino3 * @created 2014-05-044 * @version 0.15 * @license MIT6 */78// ensure jQuery has been successfully loaded9jQuery(function() {10 11 // local private scope12 (function($, undefined) {13 "use strict";14 15 16 //=============================================================================17 //=========================== Attributes ======================================18 //=============================================================================19 20 21 //=============================================================================22 //=========================== Constructor =====================================23 //=============================================================================24 25 26 /**27 * Constructor for a new jQuery.filesystem.28 * 29 * @class30 * <p>This class provides jQuery wrapping features for W3C's FileSystem API</p> 31 *32 * @constructor33 * @param {string} sDBName name of the database34 * @param {string} sRemoteIDPath a path to server's ID in object properties (mandatory to create index)35 * 36 * @name jQuery.filesystem37 */38 function filesystem() {39 if (! window.requestFileSystem) throw new Error('browser does not support FileSystem API');40 }41 42 // register plugin in jQuery namespace43 $.extend({ filesystem : filesystem });44 45 46 47 //=============================================================================48 //=========================== Constants =======================================49 //=============================================================================50 51 52 /**53 * Constant for requesting temporary filesystem54 * @name jQuery.filesystem.TEMPORARY55 */56 filesystem.TEMPORARY = 0;57 58 /**59 * Constant for requesting persistent filesystem60 * @name jQuery.filesystem.PERSISTENT61 */62 filesystem.PERSISTENT = 1;63 64 //=================================================================================================================65 66 67 /**68 * Constant for KiloByte69 * @name jQuery.filesystem.KB70 */71 filesystem.KB = 1024;72 73 /**74 * Constant for MegaByte75 * @name jQuery.filesystem.MB76 */77 filesystem.MB = 1024 * filesystem.KB;78 79 80 //=============================================================================81 //=========================== Methods =========================================82 //=============================================================================83 84 85 /**86 * Requests a filesystem in which to store application data.87 * 88 * @function89 * @name jQuery.filesystem#requestFS90 * @return {jQuery.Deferred} a request object containing the result {@link jQuery.filesystem.FileSystem} object in case of success91 */92 filesystem.prototype.requestFS = function(eType, iSize) {93 94 var oDef = $.Deferred();95 window.requestFileSystem(eType, iSize,96 $.proxy(function(oD, oFileSystem) { oD.resolve(new filesystem.FileSystem(oFileSystem)); }, null, oDef),97 filesystem._fnErrorCallback(oDef));98 99 return oDef;100 };101 102 //=================================================================================================================103 104 105 /**106 * Allows the user to look up the Entry for a file or directory referred to by a local URL.107 * 108 * @function109 * @name jQuery.filesystem#resolveURL110 * @param {string} sURL the URL of the file or directory to look up within the local file system111 * @return {jQuery.Deferred} a request object containing the result {@link jQuery.filesystem.Entry} object in case of success112 */113 filesystem.prototype.resolveURL = function(sUrl) {114 115 var oDef = $.Deferred();116 window.resolveLocalFileSystemURL(sUrl,117 filesystem._fnEntryCallback(oDef),118 filesystem._fnErrorCallback(oDef));119 120 return oDef;121 };122 123 //=================================================================================================================124 125 126 filesystem._fnEntryCallback = function(oDef, oFileSystem) {127 128 return $.proxy(function(oD, oInternFS, oEntry) {129 oD.resolve(new filesystem[oEntry.isDirectory ? 'DirectoryEntry' : 'FileEntry'](oEntry, oInternFS));130 }, null, oDef, oFileSystem);131 132 };133 134 //=================================================================================================================135 136 137 filesystem._fnErrorCallback = function(oDef) {138 139 return oDef.reject;140 };141 142 143 //=============================================================================144 //=========================== Interface FileSystem ============================145 //=============================================================================146 147 148 /**149 * Constructor for a new jQuery.filesystem.FileSystem.150 * 151 * @class152 * <p>This class provides jQuery wrapping features for FileSystem interface</p> 153 *154 * @constructor155 * @param {FileSystem} oFileSystem native <code>FileSystem</code> reference156 * 157 * @name jQuery.filesystem.FileSystem158 * 159 * @property {string} name Name of this FileSystem object160 * @property {jQuery.filesystem.DirectoryEntry} root Root of this FileSystem object161 */162 filesystem.FileSystem = function(oFileSystem) {163 164 this._fs = oFileSystem;165 166 this.name = oFileSystem.name;167 this.root = new filesystem.DirectoryEntry(oFileSystem.root, this);168 };169 170 171 //=============================================================================172 //=========================== Interface Entry =================================173 //=============================================================================174 175 176 /**177 * Constructor for a new jQuery.filesystem.Entry.178 * 179 * @class180 * <p>This class provides jQuery wrapping features for Entry interface</p> 181 *182 * @constructor183 * @param {Entry} oEntry native <code>Entry</code> reference184 * @param {jQuery.filesystem.FileSystem} [oFileSystem] optional reference to <code>FileSystem</code> object. if not provided, a new wrapper object of native FileSystem reference is created 185 * 186 * @name jQuery.filesystem.Entry187 * 188 * @property {boolean} isFile Entry is a file.189 * @property {boolean} isDirectory Entry is a directory.190 * @property {string} name The name of the entry, excluding the path leading to it.191 * @property {string} fullPath The full absolute path from the root to the entry.192 * @property {jQuery.filesystem.FileSystem} fileSystem The file system on which the entry resides.193 */194 var IEntry = filesystem.Entry = function(oEntry, oFileSystem) {195 196 this._entry = oEntry;197 198 this.isFile = oEntry.isFile;199 this.isDirectory = oEntry.isDirectory;200 this.name = oEntry.name;201 this.fullPath = oEntry.fullPath;202 this.fileSystem = oFileSystem || new filesystem.FileSystem(oEntry.fileSystem);203 };204 205 //=================================================================================================================206 207 /**208 * Look up metadata about this entry.209 * 210 * @function211 * @name jQuery.filesystem.Entry#getMetaData212 * @return {jQuery.Deferred} a request object containing the result Metadata object in case of success213 */214 IEntry.prototype.getMetaData = function() {215 216 var oDef = $.Deferred();217 this._entry.getMetadata(oDef.resolve, filesystem._fnErrorCallback(oDef));218 219 return oDef;220 };221 222 //=================================================================================================================223 224 225 /**226 * Look up the parent DirectoryEntry containing this Entry. 227 * If this Entry is the root of its filesystem, its parent is itself.228 * 229 * @function230 * @name jQuery.filesystem.Entry#getParent231 * @return {jQuery.Deferred} a request object containing the result {@link jQuery.filesystem.DirectoryEntry} object in case of success232 */233 IEntry.prototype.getParent = function() {234 235 var oDef = $.Deferred();236 237 if (this._entry.fileSystem.root === this._entry)238 oDef.resolve(this);239 else {240 this._entry.getParent(241 filesystem._fnEntryCallback(oDef, this.fileSystem),242 filesystem._fnErrorCallback(oDef));243 }244 245 return oDef;246 };247 248 //=================================================================================================================249 250 251 /**252 * Copy an entry to a different location on the file system.253 * 254 * @function255 * @name jQuery.filesystem.Entry#copyTo256 * @param {jQuery.filesystem.DirectoryEntry} oParent directory where the {@link jQuery.filesystem.Entry} should be copied to257 * @param {string} sNewName new name of the copied {@link jQuery.filesystem.Entry}. Default is its original name.258 * @return {jQuery.Deferred} a request object containing the result {@link jQuery.filesystem.Entry} object in case of success259 */260 IEntry.prototype.copyTo = function(oParent, sNewName) {261 262 var oDef = $.Deferred();263 this._entry.copyTo(oParent._entry, sNewName,264 filesystem._fnEntryCallback(oDef, oParent.fileSystem),265 filesystem._fnErrorCallback(oDef));266 267 return oDef;268 };269 270 //=================================================================================================================271 272 273 /**274 * Move an entry to a different location on the file system.275 * 276 * @function277 * @name jQuery.filesystem.Entry#moveTo278 * @param {jQuery.filesystem.DirectoryEntry} oParent directory where the {@link jQuery.filesystem.Entry} should be moved to279 * @param {string} sNewName new name of the copied {@link jQuery.filesystem.Entry}. Default is its original name.280 * @return {jQuery.Deferred} a request object containing the result {@link jQuery.filesystem.Entry} object in case of success281 */282 IEntry.prototype.moveTo = function(oParent, sNewName) {283 284 var oDef = $.Deferred();285 this._entry.moveTo(oParent._entry, sNewName,286 filesystem._fnEntryCallback(oDef, oParent.fileSystem),287 filesystem._fnErrorCallback(oDef));288 289 return oDef;290 };291 292 //=================================================================================================================293 294 295 /**296 * Deletes a file or directory.297 * 298 * @function299 * @name jQuery.filesystem.Entry#remove300 * @return {jQuery.Deferred} the request object301 */302 IEntry.prototype.remove = function() {303 304 var oDef = $.Deferred();305 this._entry.remove(306 oDef.resolve,307 filesystem._fnErrorCallback(oDef));308 309 return oDef;310 };311 312 313 //=============================================================================314 //=========================== Interface DirectoryEntry ========================315 //=============================================================================316 317 318 319 /**320 * Constructor for a new jQuery.filesystem.DirectoryEntry.321 * 322 * @class323 * <p>This class provides jQuery wrapping features for DirectoryEntry interface</p> 324 *325 * @extends jQuery.filesystem.Entry326 * 327 * @constructor328 * @param {Entry} oEntry native <code>Entry</code> reference329 * @param {jQuery.filesystem.FileSystem} [oFileSystem] optional reference to <code>FileSystem</code> object. if not provided, a new wrapper object of native FileSystem reference is created 330 * 331 * @name jQuery.filesystem.DirectoryEntry332 */333 var IDEntry = filesystem.DirectoryEntry = function(oEntry, oFileSystem) {334 335 // super()336 filesystem.Entry.apply(this, arguments);337 };338 339 340 /*341 * Inheritance from filesystem.Entry342 */343 IDEntry.prototype = Object.create(filesystem.Entry.prototype);344 IDEntry.prototype.constructor = IDEntry;345 346 //=================================================================================================================347 348 349 /**350 * Looks up a file.351 * 352 * @function353 * @name jQuery.filesystem.DirectoryEntry#getFile354 * @param {string} sPath either an absolute path or a relative path from this directory to the file to be looked up355 * @param {boolean} bCreateIfNotExists whether the looked up file should be created if it does not exist, or not356 * @return {jQuery.Deferred} a request object containing the result {@link jQuery.filesystem.FileEntry} object in case of success357 */358 IDEntry.prototype.getFile = function(sPath, bCreateIfNotExists) {359 360 var oDef = $.Deferred();361 362 this._entry.getFile(sPath, { create : !!bCreateIfNotExists },363 filesystem._fnEntryCallback(oDef, this.fileSystem),364 filesystem._fnErrorCallback(oDef));365 366 return oDef;367 };368 369 //=================================================================================================================370 371 372 /**373 * Looks up a directory.374 * 375 * @function376 * @name jQuery.filesystem.DirectoryEntry#getDirectory377 * @param {string} sPath either an absolute path or a relative path from this directory to the directory to be looked up378 * @param {boolean} bCreateIfNotExists whether the looked up directory should be created if it does not exist, or not379 * @return {jQuery.Deferred} a request object containing the result {@link jQuery.filesystem.DirectoryEntry} object in case of success380 */381 IDEntry.prototype.getDirectory = function(sPath, bCreateIfNotExists) {382 383 var oDef = $.Deferred();384 385 this._entry.getDirectory(sPath, { create : !!bCreateIfNotExists },386 filesystem._fnEntryCallback(oDef, this.fileSystem),387 filesystem._fnErrorCallback(oDef));388 389 return oDef;390 };391 392 //=================================================================================================================393 394 395 /**396 * Creates a file.397 * 398 * @function399 * @name jQuery.filesystem.DirectoryEntry#createFile400 * @param {string} sPath either an absolute path or a relative path from this directory to the file to be created401 * @return {jQuery.Deferred} a request object containing the result {@link jQuery.filesystem.FileEntry} object in case of success402 */403 IDEntry.prototype.createFile = function(sPath) {404 405 var oDef = $.Deferred();406 407 this._entry.getFile(sPath, { create : true, exclusive : true },408 filesystem._fnEntryCallback(oDef, this.fileSystem),409 filesystem._fnErrorCallback(oDef));410 411 return oDef;412 };413 414 //=================================================================================================================415 416 417 /**418 * Creates a directory.419 * 420 * @function421 * @name jQuery.filesystem.DirectoryEntry#createDirectory422 * @param {string} sPath either an absolute path or a relative path from this directory to the directory to be created423 * @return {jQuery.Deferred} a request object containing the result {@link jQuery.filesystem.DirectoryEntry} object in case of success424 */425 IDEntry.prototype.createDirectory = function(sPath) {426 427 var oDef = $.Deferred();428 429 this._entry.getDirectory(sPath, { create : true, exclusive : true },430 filesystem._fnEntryCallback(oDef, this.fileSystem),431 filesystem._fnErrorCallback(oDef));432 433 return oDef;434 };435 436 //=================================================================================================================437 438 439 /**440 * Deletes a directory and all of its contents, if any.441 * 442 * @function443 * @name jQuery.filesystem.DirectoryEntry#removeRecursively444 * @return {jQuery.Deferred} a request object445 */446 IDEntry.prototype.removeRecursively = function() {447 448 var oDef = $.Deferred();449 this._entry.removeRecursively(450 oDef.resolve,451 filesystem._fnErrorCallback(oDef));452 453 return oDef;454 };455 456 //=================================================================================================================457 458 459 /**460 * Lists files and directories in a directory.461 * 462 * @function463 * @name jQuery.filesystem.DirectoryEntry#listContent464 * @return {jQuery.Deferred} a request object containing the result {@link jQuery.filesystem.Entry[]} array in case of success465 */466 IDEntry.prototype.listContent = function() {467 468 var oDef = $.Deferred(),469 oReader = new filesystem.DirectoryReader(this._entry.createReader()),470 471 aDirContent = [],472 473 // define recursive function to read all content474 fnReadBlock = function(oD, oReader, aContent) {475 476 oReader.readEntries()477 .done($.proxy(478 function(oDeferred, oReader, aList, aResults) {479 480 var i = 0, len = aResults.length;481 482 for ( ; i < len ; ++i) aList.push(aResults[i]);483 484 if (len) {485 // fetch next block486 fnReadBlock(oDeferred, oReader, aList);487 } else {488 // end of content reading489 oDeferred.resolve(aList);490 }491 492 }, this, oD, oReader, aContent)493 )494 .fail(filesystem._fnErrorCallback(oD));495 };496 497 498 // start reading content499 fnReadBlock(oDef, oReader, aDirContent);500 501 return oDef;502 };503 504 505 //=============================================================================506 //=========================== Interface DirectoryReader =======================507 //=============================================================================508 509 510 /**511 * Constructor for a new jQuery.filesystem.DirectoryReader.512 * 513 * @class514 * <p>This class provides jQuery wrapping features for DirectoryReader interface</p> 515 *516 * @constructor517 * @param {DirectoryReader} oDReader native <code>DirectoryReader</code> reference518 * 519 * @name jQuery.filesystem.DirectoryReader520 */521 var IDReader = filesystem.DirectoryReader = function(oDReader) {522 523 this._reader = oDReader;524 };525 526 //=================================================================================================================527 528 529 /**530 * Read the next block of entries from this directory.531 * 532 * @function533 * @name jQuery.filesystem.DirectoryReader#readEntries534 * @return {jQuery.Deferred} a request object containing the result {@link jQuery.filesystem.Entry[]} array in case of success535 */536 IDReader.prototype.readEntries = function() {537 538 var oDef = $.Deferred();539 540 this._reader.readEntries(oDef.resolve, oDef.reject);541 542 return oDef;543 };544 545 546 //=============================================================================547 //=========================== Interface FileEntry =============================548 //=============================================================================549 550 551 /**552 * Constructor for a new jQuery.filesystem.FileEntry.553 * 554 * @class555 * <p>This class provides jQuery wrapping features for FileEntry interface</p> 556 *557 * @extends jQuery.filesystem.Entry558 * 559 * @constructor560 * @param {Entry} oEntry native <code>Entry</code> reference561 * @param {jQuery.filesystem.FileSystem} [oFileSystem] optional reference to <code>FileSystem</code> object. if not provided, a new wrapper object of native FileSystem reference is created 562 * 563 * @name jQuery.filesystem.FileEntry564 */565 var IFEntry = filesystem.FileEntry = function(oEntry, oFileSystem) {566 567 // super()568 filesystem.Entry.apply(this, arguments);569 };570 571 572 /*573 * Inheritance from filesystem.Entry574 */575 IFEntry.prototype = Object.create(filesystem.Entry.prototype);576 IFEntry.prototype.constructor = IFEntry;577 578 //=================================================================================================================579 580 581 /**582 * Creates a new FileWriter associated with the file that this FileEntry represents.583 * 584 * @function585 * @name jQuery.filesystem.FileEntry#createWriter586 * @return {jQuery.Deferred} a request object containing the result {@link FileWriter} object in case of success587 */588 IFEntry.prototype.createWriter = function() {589 590 var oDef = $.Deferred();591 592 this._entry.createWriter(593 oDef.resolve,594 filesystem._fnErrorCallback(oDef));595 596 return oDef;597 };598 599 //=================================================================================================================600 601 602 /**603 * Returns a <code>File</code> that represents the current state of the file that this FileEntry represents.604 * 605 * @function606 * @name jQuery.filesystem.FileEntry#asFile607 * @return {jQuery.Deferred} a request object containing the result {@link jQuery.filesystem.File} object in case of success608 */609 IFEntry.prototype.asFile = function() {610 611 var oDef = $.Deferred();612 613 this._entry.file(614 oDef.resolve,615 filesystem._fnErrorCallback(oDef));616 617 return oDef;618 };619 620 621 //=============================================================================622 //=========================== Helpers =========================================623 //=============================================================================624 625 626 627 })(jQuery) ...

Full Screen

Full Screen

fake_filesystem_shutil_test.py

Source:fake_filesystem_shutil_test.py Github

copy

Full Screen

1#!/usr/bin/python2.42#3# Copyright 2009 Google Inc. All Rights Reserved.4#5# Licensed under the Apache License, Version 2.0 (the "License");6# you may not use this file except in compliance with the License.7# You may obtain a copy of the License at8#9# http://www.apache.org/licenses/LICENSE-2.010#11# Unless required by applicable law or agreed to in writing, software12# distributed under the License is distributed on an "AS IS" BASIS,13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.14# See the License for the specific language governing permissions and15# limitations under the License.16"""Unittest for fake_filesystem_shutil."""17import os18import stat19import time20import unittest21import fake_filesystem22import fake_filesystem_shutil23class FakeShutilModuleTest(unittest.TestCase):24 def setUp(self):25 self.filesystem = fake_filesystem.FakeFilesystem()26 self.shutil = fake_filesystem_shutil.FakeShutilModule(self.filesystem)27 def testRmtree(self):28 directory = 'xyzzy'29 self.filesystem.CreateDirectory(directory)30 self.filesystem.CreateDirectory(os.path.join(directory, 'subdir'))31 self.filesystem.CreateFile(os.path.join(directory, 'subfile'))32 self.assertTrue(self.filesystem.Exists(directory))33 self.shutil.rmtree(directory)34 self.assertFalse(self.filesystem.Exists(directory))35 def testCopy(self):36 src_file = 'xyzzy'37 dst_file = 'xyzzy_copy'38 src_obj = self.filesystem.CreateFile(src_file)39 src_obj.st_mode = ((src_obj.st_mode & ~0o7777) | 0o750)40 self.assertTrue(self.filesystem.Exists(src_file))41 self.assertFalse(self.filesystem.Exists(dst_file))42 self.shutil.copy(src_file, dst_file)43 self.assertTrue(self.filesystem.Exists(dst_file))44 dst_obj = self.filesystem.GetObject(dst_file)45 self.assertEqual(src_obj.st_mode, dst_obj.st_mode)46 def testCopyDirectory(self):47 src_file = 'xyzzy'48 parent_directory = 'parent'49 dst_file = os.path.join(parent_directory, src_file)50 src_obj = self.filesystem.CreateFile(src_file)51 self.filesystem.CreateDirectory(parent_directory)52 src_obj.st_mode = ((src_obj.st_mode & ~0o7777) | 0o750)53 self.assertTrue(self.filesystem.Exists(src_file))54 self.assertTrue(self.filesystem.Exists(parent_directory))55 self.assertFalse(self.filesystem.Exists(dst_file))56 self.shutil.copy(src_file, parent_directory)57 self.assertTrue(self.filesystem.Exists(dst_file))58 dst_obj = self.filesystem.GetObject(dst_file)59 self.assertEqual(src_obj.st_mode, dst_obj.st_mode)60 def testCopystat(self):61 src_file = 'xyzzy'62 dst_file = 'xyzzy_copy'63 src_obj = self.filesystem.CreateFile(src_file)64 dst_obj = self.filesystem.CreateFile(dst_file)65 src_obj.st_mode = ((src_obj.st_mode & ~0o7777) | 0o750)66 src_obj.st_uid = 12367 src_obj.st_gid = 12368 src_obj.st_atime = time.time()69 src_obj.st_mtime = time.time()70 self.assertTrue(self.filesystem.Exists(src_file))71 self.assertTrue(self.filesystem.Exists(dst_file))72 self.shutil.copystat(src_file, dst_file)73 self.assertEqual(src_obj.st_mode, dst_obj.st_mode)74 self.assertEqual(src_obj.st_uid, dst_obj.st_uid)75 self.assertEqual(src_obj.st_gid, dst_obj.st_gid)76 self.assertEqual(src_obj.st_atime, dst_obj.st_atime)77 self.assertEqual(src_obj.st_mtime, dst_obj.st_mtime)78 def testCopy2(self):79 src_file = 'xyzzy'80 dst_file = 'xyzzy_copy'81 src_obj = self.filesystem.CreateFile(src_file)82 src_obj.st_mode = ((src_obj.st_mode & ~0o7777) | 0o750)83 src_obj.st_uid = 12384 src_obj.st_gid = 12385 src_obj.st_atime = time.time()86 src_obj.st_mtime = time.time()87 self.assertTrue(self.filesystem.Exists(src_file))88 self.assertFalse(self.filesystem.Exists(dst_file))89 self.shutil.copy2(src_file, dst_file)90 self.assertTrue(self.filesystem.Exists(dst_file))91 dst_obj = self.filesystem.GetObject(dst_file)92 self.assertEqual(src_obj.st_mode, dst_obj.st_mode)93 self.assertEqual(src_obj.st_uid, dst_obj.st_uid)94 self.assertEqual(src_obj.st_gid, dst_obj.st_gid)95 self.assertEqual(src_obj.st_atime, dst_obj.st_atime)96 self.assertEqual(src_obj.st_mtime, dst_obj.st_mtime)97 def testCopy2Directory(self):98 src_file = 'xyzzy'99 parent_directory = 'parent'100 dst_file = os.path.join(parent_directory, src_file)101 src_obj = self.filesystem.CreateFile(src_file)102 self.filesystem.CreateDirectory(parent_directory)103 src_obj.st_mode = ((src_obj.st_mode & ~0o7777) | 0o750)104 src_obj.st_uid = 123105 src_obj.st_gid = 123106 src_obj.st_atime = time.time()107 src_obj.st_mtime = time.time()108 self.assertTrue(self.filesystem.Exists(src_file))109 self.assertTrue(self.filesystem.Exists(parent_directory))110 self.assertFalse(self.filesystem.Exists(dst_file))111 self.shutil.copy2(src_file, parent_directory)112 self.assertTrue(self.filesystem.Exists(dst_file))113 dst_obj = self.filesystem.GetObject(dst_file)114 self.assertEqual(src_obj.st_mode, dst_obj.st_mode)115 self.assertEqual(src_obj.st_uid, dst_obj.st_uid)116 self.assertEqual(src_obj.st_gid, dst_obj.st_gid)117 self.assertEqual(src_obj.st_atime, dst_obj.st_atime)118 self.assertEqual(src_obj.st_mtime, dst_obj.st_mtime)119 def testCopytree(self):120 src_directory = 'xyzzy'121 dst_directory = 'xyzzy_copy'122 self.filesystem.CreateDirectory(src_directory)123 self.filesystem.CreateDirectory(os.path.join(src_directory, 'subdir'))124 self.filesystem.CreateFile(os.path.join(src_directory, 'subfile'))125 self.assertTrue(self.filesystem.Exists(src_directory))126 self.assertFalse(self.filesystem.Exists(dst_directory))127 self.shutil.copytree(src_directory, dst_directory)128 self.assertTrue(self.filesystem.Exists(dst_directory))129 self.assertTrue(self.filesystem.Exists(os.path.join(dst_directory,130 'subdir')))131 self.assertTrue(self.filesystem.Exists(os.path.join(dst_directory,132 'subfile')))133 def testCopytreeSrcIsFile(self):134 src_file = 'xyzzy'135 dst_directory = 'xyzzy_copy'136 self.filesystem.CreateFile(src_file)137 self.assertTrue(self.filesystem.Exists(src_file))138 self.assertFalse(self.filesystem.Exists(dst_directory))139 self.assertRaises(OSError,140 self.shutil.copytree,141 src_file,142 dst_directory)143 def testMoveFile(self):144 src_file = 'original_xyzzy'145 dst_file = 'moved_xyzzy'146 self.filesystem.CreateFile(src_file)147 self.assertTrue(self.filesystem.Exists(src_file))148 self.assertFalse(self.filesystem.Exists(dst_file))149 self.shutil.move(src_file, dst_file)150 self.assertTrue(self.filesystem.Exists(dst_file))151 self.assertFalse(self.filesystem.Exists(src_file))152 def testMoveFileIntoDirectory(self):153 src_file = 'xyzzy'154 dst_directory = 'directory'155 dst_file = os.path.join(dst_directory, src_file)156 self.filesystem.CreateFile(src_file)157 self.filesystem.CreateDirectory(dst_directory)158 self.assertTrue(self.filesystem.Exists(src_file))159 self.assertFalse(self.filesystem.Exists(dst_file))160 self.shutil.move(src_file, dst_directory)161 self.assertTrue(self.filesystem.Exists(dst_file))162 self.assertFalse(self.filesystem.Exists(src_file))163 def testMoveDirectory(self):164 src_directory = 'original_xyzzy'165 dst_directory = 'moved_xyzzy'166 self.filesystem.CreateDirectory(src_directory)167 self.filesystem.CreateFile(os.path.join(src_directory, 'subfile'))168 self.filesystem.CreateDirectory(os.path.join(src_directory, 'subdir'))169 self.assertTrue(self.filesystem.Exists(src_directory))170 self.assertFalse(self.filesystem.Exists(dst_directory))171 self.shutil.move(src_directory, dst_directory)172 self.assertTrue(self.filesystem.Exists(dst_directory))173 self.assertTrue(self.filesystem.Exists(os.path.join(dst_directory,174 'subfile')))175 self.assertTrue(self.filesystem.Exists(os.path.join(dst_directory,176 'subdir')))177 self.assertFalse(self.filesystem.Exists(src_directory))178class CopyFileTest(unittest.TestCase):179 def setUp(self):180 self.filesystem = fake_filesystem.FakeFilesystem()181 self.shutil = fake_filesystem_shutil.FakeShutilModule(self.filesystem)182 def testCommonCase(self):183 src_file = 'xyzzy'184 dst_file = 'xyzzy_copy'185 contents = 'contents of file'186 self.filesystem.CreateFile(src_file, contents=contents)187 self.assertTrue(self.filesystem.Exists(src_file))188 self.assertFalse(self.filesystem.Exists(dst_file))189 self.shutil.copyfile(src_file, dst_file)190 self.assertTrue(self.filesystem.Exists(dst_file))191 self.assertEqual(contents, self.filesystem.GetObject(dst_file).contents)192 def testRaisesIfSourceAndDestAreTheSameFile(self):193 src_file = 'xyzzy'194 dst_file = src_file195 contents = 'contents of file'196 self.filesystem.CreateFile(src_file, contents=contents)197 self.assertTrue(self.filesystem.Exists(src_file))198 self.assertRaises(self.shutil.Error,199 self.shutil.copyfile, src_file, dst_file)200 def testRaisesIfDestIsASymlinkToSrc(self):201 src_file = '/tmp/foo'202 dst_file = '/tmp/bar'203 contents = 'contents of file'204 self.filesystem.CreateFile(src_file, contents=contents)205 self.filesystem.CreateLink(dst_file, src_file)206 self.assertTrue(self.filesystem.Exists(src_file))207 self.assertRaises(self.shutil.Error,208 self.shutil.copyfile, src_file, dst_file)209 def testSucceedsIfDestExistsAndIsWritable(self):210 src_file = 'xyzzy'211 dst_file = 'xyzzy_copy'212 src_contents = 'contents of source file'213 dst_contents = 'contents of dest file'214 self.filesystem.CreateFile(src_file, contents=src_contents)215 self.filesystem.CreateFile(dst_file, contents=dst_contents)216 self.assertTrue(self.filesystem.Exists(src_file))217 self.assertTrue(self.filesystem.Exists(dst_file))218 self.shutil.copyfile(src_file, dst_file)219 self.assertTrue(self.filesystem.Exists(dst_file))220 self.assertEqual(src_contents,221 self.filesystem.GetObject(dst_file).contents)222 def testRaisesIfDestExistsAndIsNotWritable(self):223 src_file = 'xyzzy'224 dst_file = 'xyzzy_copy'225 src_contents = 'contents of source file'226 dst_contents = 'contents of dest file'227 self.filesystem.CreateFile(src_file, contents=src_contents)228 self.filesystem.CreateFile(dst_file,229 st_mode=stat.S_IFREG | 0o400,230 contents=dst_contents)231 self.assertTrue(self.filesystem.Exists(src_file))232 self.assertTrue(self.filesystem.Exists(dst_file))233 self.assertRaises(IOError, self.shutil.copyfile, src_file, dst_file)234 def testRaisesIfDestDirIsNotWritable(self):235 src_file = 'xyzzy'236 dst_dir = '/tmp/foo'237 dst_file = os.path.join(dst_dir, src_file)238 src_contents = 'contents of source file'239 self.filesystem.CreateFile(src_file, contents=src_contents)240 self.filesystem.CreateDirectory(dst_dir, perm_bits=0o555)241 self.assertTrue(self.filesystem.Exists(src_file))242 self.assertTrue(self.filesystem.Exists(dst_dir))243 self.assertRaises(IOError, self.shutil.copyfile, src_file, dst_file)244 def testRaisesIfSrcDoesntExist(self):245 src_file = 'xyzzy'246 dst_file = 'xyzzy_copy'247 self.assertFalse(self.filesystem.Exists(src_file))248 self.assertRaises(IOError, self.shutil.copyfile, src_file, dst_file)249 def testRaisesIfSrcNotReadable(self):250 src_file = 'xyzzy'251 dst_file = 'xyzzy_copy'252 src_contents = 'contents of source file'253 self.filesystem.CreateFile(src_file,254 st_mode=stat.S_IFREG | 0o000,255 contents=src_contents)256 self.assertTrue(self.filesystem.Exists(src_file))257 self.assertRaises(IOError, self.shutil.copyfile, src_file, dst_file)258 def testRaisesIfSrcIsADirectory(self):259 src_file = 'xyzzy'260 dst_file = 'xyzzy_copy'261 self.filesystem.CreateDirectory(src_file)262 self.assertTrue(self.filesystem.Exists(src_file))263 self.assertRaises(IOError, self.shutil.copyfile, src_file, dst_file)264 def testRaisesIfDestIsADirectory(self):265 src_file = 'xyzzy'266 dst_dir = '/tmp/foo'267 src_contents = 'contents of source file'268 self.filesystem.CreateFile(src_file, contents=src_contents)269 self.filesystem.CreateDirectory(dst_dir)270 self.assertTrue(self.filesystem.Exists(src_file))271 self.assertTrue(self.filesystem.Exists(dst_dir))272 self.assertRaises(IOError, self.shutil.copyfile, src_file, dst_dir)273if __name__ == '__main__':...

Full Screen

Full Screen

test-filesystem.js

Source:test-filesystem.js Github

copy

Full Screen

1import Util from './lib/util.js';2import PortableFileSystem, { SEEK_SET, SEEK_END } from './lib/filesystem.js';3import ConsoleSetup from './lib/consoleSetup.js';4import TinyTest, { run, assert, assertEquals } from './lib/tinyTest.js';5let filesystem;6let tmpdir;7let buffer, buffer2;8let handle;9let data = 'TEST\nabcdefg\n123456789';10let data2;11const tests = {12 'filesystem.buffer': () => {13 buffer = filesystem.buffer(4096);14 assert(buffer);15 },16 'filesystem.bufferSize': () => {17 assertEquals(filesystem.bufferSize(buffer), 4096);18 },19 'filesystem.bufferFrom': () => {20 buffer2 = filesystem.bufferFrom('abcdefg\n');21 assertEquals(filesystem.bufferSize(buffer2), 8);22 data2 = filesystem.bufferFrom(data);23 assertEquals(filesystem.bufferSize(data2), data.length);24 },25 'filesystem.bufferToString': () => {26 assertEquals(filesystem.bufferToString(buffer2), 'abcdefg\n');27 },28 'filesystem.mkdir': () => {29 assert(!(filesystem.mkdir(tmpdir, 0o1777) < 0), `mkdir("${tmpdir}", 0o1777) < 0`);30 },31 'filesystem.exists': () => {32 assert(filesystem.exists(tmpdir));33 },34 'filesystem.open': () => {35 assert((handle = filesystem.open(tmpdir + '/rdwr', 'w+')) != null, `open("${tmpdir}/rdwr", "w+") == null`);36 },37 'filesystem.write': () => {38 assertEquals(filesystem.write(handle, data), data.length);39 },40 'filesystem.seek': () => {41 assertEquals(filesystem.seek(handle, 5, SEEK_SET), 5);42 },43 'filesystem.tell': () => {44 assertEquals(filesystem.tell(handle), 5);45 },46 'filesystem.read': () => {47 let ret, str;48 for(let str of ['abcdefg\n', '123456789']) {49 ret = filesystem.read(handle, buffer, 0, str.length);50 assertEquals(ret, str.length);51 assertEquals(filesystem.bufferToString(buffer).slice(0, ret), str);52 }53 },54 'filesystem.close': () => {55 assertEquals(filesystem.close(handle), 0);56 },57 'filesystem.readFile': () => {58 assertEquals(filesystem.readFile(tmpdir + '/rdwr'), data);59 },60 'filesystem.writeFile': () => {61 let name = tmpdir + '/wrf';62 let ret = filesystem.writeFile(name, data);63 let d = filesystem.readFile(name, null);64 assertEquals(filesystem.bufferToString(d), data);65 },66 'filesystem.size': () => {67 assertEquals(filesystem.size(tmpdir + '/wrf'), data.length);68 },69 'filesystem.symlink': () => {70 assertEquals(filesystem.symlink('..', tmpdir + '/link'), 0);71 assertEquals(filesystem.symlink('wrf', tmpdir + '/file'), 0);72 },73 'filesystem.readlink': () => {74 assertEquals(filesystem.readlink(tmpdir + '/link'), '..');75 },76 'filesystem.realpath': () => {77 assertEquals(filesystem.realpath(tmpdir + '/link'), '/tmp');78 },79 'filesystem.chdir': () => {80 assertEquals(filesystem.chdir(tmpdir), 0);81 },82 'filesystem.getcwd': () => {83 assertEquals(filesystem.getcwd(), tmpdir);84 },85 'filesystem.readdir': () => {86 assertEquals(filesystem.readdir('.').sort().join(','), '.,..,file,link,rdwr,wrf');87 },88 'filesystem.rename': () => {89 assertEquals(filesystem.rename('link', 'link2'), 0);90 assert(filesystem.exists('link2'));91 },92 'filesystem.stat': () => {93 let st;94 assert(filesystem.stat(tmpdir).isDirectory());95 st = filesystem.stat(tmpdir + '/file');96 // console.log("st:", Util.inspect(st));97 assert(st.isFile());98 },99 'filesystem.lstat': () => {100 assert(filesystem.lstat(tmpdir + '/file').isSymbolicLink());101 },102 'filesystem.unlink': () => {103 for(let file of filesystem.readdir(tmpdir)) {104 if(file[0] == '.') continue;105 let path = `${tmpdir}/${file}`;106 assertEquals(filesystem.unlink(path), 0);107 assert(!filesystem.exists(path));108 }109 assertEquals(filesystem.unlink(tmpdir), 0);110 assert(!filesystem.exists(tmpdir));111 },112 'filesystem.isatty': () => {113 let fd = filesystem.open('/dev/stderr');114 //console.log('errstr:', filesystem.errstr);115 assertEquals(filesystem.isatty(fd || filesystem.open('/dev/tty')), true);116 assert(!filesystem.isatty(filesystem.open('/dev/null')));117 },118 'filesystem.mkdtemp': () => {119 let tmp = filesystem.mkdtemp('/tmp/aaaa');120 console.log('tmp:', tmp);121 assert(filesystem.exists(tmp));122 assert(filesystem.stat(tmp).isDirectory());123 assertEquals(filesystem.unlink(tmp), 0);124 assert(!filesystem.exists(tmp));125 },126 'filesystem.stdin': () => {127 let file = filesystem.stdin;128 assertEquals(filesystem.fileno(file), 0);129 },130 'filesystem.stdout': () => {131 let file = filesystem.stdout;132 assertEquals(filesystem.fileno(file), 1);133 },134 'filesystem.stderr': () => {135 let file = filesystem.stderr;136 assertEquals(filesystem.fileno(file), 2);137 }138};139async function main(...args) {140 await ConsoleSetup({ colors: true, depth: Infinity });141 await PortableFileSystem(fs => (filesystem = fs));142 // globalThis.console = {};143 console.log('Console:', Object.getPrototypeOf(console));144 console.log('log:', Object.getPrototypeOf(console).log);145 console.log(146 'ARGS:',147 new Map([148 ['a', 1],149 ['b', 2]150 ]),151 { u: undefined, n: null, args: Util.getArgs(), filesystem }152 );153 tmpdir = `/tmp/${Util.randStr(10)}`;154 TinyTest.run(Util.filter(tests, t => t));155 return;156 console.log(157 Util.getMethodNames(filesystem)158 .map(n => ` 'filesystem.${n}': null,`)159 .join('\n')160 );161}...

Full Screen

Full Screen

file_system_custom_bindings.js

Source:file_system_custom_bindings.js Github

copy

Full Screen

1// Copyright (c) 2012 The Chromium Authors. All rights reserved.2// Use of this source code is governed by a BSD-style license that can be3// found in the LICENSE file.4// Custom binding for the fileSystem API.5var binding = require('binding').Binding.create('fileSystem');6var sendRequest = require('sendRequest');7var getFileBindingsForApi =8 require('fileEntryBindingUtil').getFileBindingsForApi;9var fileBindings = getFileBindingsForApi('fileSystem');10var bindFileEntryCallback = fileBindings.bindFileEntryCallback;11var entryIdManager = fileBindings.entryIdManager;12var fileSystemNatives = requireNative('file_system_natives');13binding.registerCustomHook(function(bindingsAPI) {14 var apiFunctions = bindingsAPI.apiFunctions;15 var fileSystem = bindingsAPI.compiledApi;16 function bindFileEntryFunction(functionName) {17 apiFunctions.setUpdateArgumentsPostValidate(18 functionName, function(fileEntry, callback) {19 var fileSystemName = fileEntry.filesystem.name;20 var relativePath = $String.slice(fileEntry.fullPath, 1);21 return [fileSystemName, relativePath, callback];22 });23 }24 $Array.forEach(['getDisplayPath', 'getWritableEntry', 'isWritableEntry'],25 bindFileEntryFunction);26 $Array.forEach(['getWritableEntry', 'chooseEntry', 'restoreEntry'],27 function(functionName) {28 bindFileEntryCallback(functionName, apiFunctions);29 });30 apiFunctions.setHandleRequest('retainEntry', function(fileEntry) {31 var id = entryIdManager.getEntryId(fileEntry);32 if (!id)33 return '';34 var fileSystemName = fileEntry.filesystem.name;35 var relativePath = $String.slice(fileEntry.fullPath, 1);36 sendRequest.sendRequest(this.name, [id, fileSystemName, relativePath],37 this.definition.parameters, {});38 return id;39 });40 apiFunctions.setHandleRequest('isRestorable',41 function(id, callback) {42 var savedEntry = entryIdManager.getEntryById(id);43 if (savedEntry) {44 sendRequest.safeCallbackApply(45 'fileSystem.isRestorable',46 {},47 callback,48 [true]);49 } else {50 sendRequest.sendRequest(51 this.name, [id, callback], this.definition.parameters, {});52 }53 });54 apiFunctions.setUpdateArgumentsPostValidate('restoreEntry',55 function(id, callback) {56 var savedEntry = entryIdManager.getEntryById(id);57 if (savedEntry) {58 // We already have a file entry for this id so pass it to the callback and59 // send a request to the browser to move it to the back of the LRU.60 sendRequest.safeCallbackApply(61 'fileSystem.restoreEntry',62 {},63 callback,64 [savedEntry]);65 return [id, false, null];66 } else {67 // Ask the browser process for a new file entry for this id, to be passed68 // to |callback|.69 return [id, true, callback];70 }71 });72 apiFunctions.setCustomCallback('requestFileSystem',73 function(name, request, callback, response) {74 var fileSystem;75 if (response && response.file_system_id) {76 fileSystem = fileSystemNatives.GetIsolatedFileSystem(77 response.file_system_id, response.file_system_path);78 }79 sendRequest.safeCallbackApply(80 'fileSystem.requestFileSystem',81 request,82 callback,83 [fileSystem]);84 });85 // TODO(benwells): Remove these deprecated versions of the functions.86 fileSystem.getWritableFileEntry = function() {87 console.log("chrome.fileSystem.getWritableFileEntry is deprecated");88 console.log("Please use chrome.fileSystem.getWritableEntry instead");89 $Function.apply(fileSystem.getWritableEntry, this, arguments);90 };91 fileSystem.isWritableFileEntry = function() {92 console.log("chrome.fileSystem.isWritableFileEntry is deprecated");93 console.log("Please use chrome.fileSystem.isWritableEntry instead");94 $Function.apply(fileSystem.isWritableEntry, this, arguments);95 };96 fileSystem.chooseFile = function() {97 console.log("chrome.fileSystem.chooseFile is deprecated");98 console.log("Please use chrome.fileSystem.chooseEntry instead");99 $Function.apply(fileSystem.chooseEntry, this, arguments);100 };101});102exports.bindFileEntryCallback = bindFileEntryCallback;...

Full Screen

Full Screen

filesystem.py

Source:filesystem.py Github

copy

Full Screen

1# -*- coding: utf-8 -*-2"""3 werkzeug.filesystem4 ~~~~~~~~~~~~~~~~~~~5 Various utilities for the local filesystem.6 :copyright: (c) 2015 by the Werkzeug Team, see AUTHORS for more details.7 :license: BSD, see LICENSE for more details.8"""9import codecs10import sys11import warnings12# We do not trust traditional unixes.13has_likely_buggy_unicode_filesystem = \14 sys.platform.startswith('linux') or 'bsd' in sys.platform15def _is_ascii_encoding(encoding):16 """17 Given an encoding this figures out if the encoding is actually ASCII (which18 is something we don't actually want in most cases). This is necessary19 because ASCII comes under many names such as ANSI_X3.4-1968.20 """21 if encoding is None:22 return False23 try:24 return codecs.lookup(encoding).name == 'ascii'25 except LookupError:26 return False27class BrokenFilesystemWarning(RuntimeWarning, UnicodeWarning):28 '''The warning used by Werkzeug to signal a broken filesystem. Will only be29 used once per runtime.'''30_warned_about_filesystem_encoding = False31def get_filesystem_encoding():32 """33 Returns the filesystem encoding that should be used. Note that this is34 different from the Python understanding of the filesystem encoding which35 might be deeply flawed. Do not use this value against Python's unicode APIs36 because it might be different. See :ref:`filesystem-encoding` for the exact37 behavior.38 The concept of a filesystem encoding in generally is not something you39 should rely on. As such if you ever need to use this function except for40 writing wrapper code reconsider.41 """42 global _warned_about_filesystem_encoding43 rv = sys.getfilesystemencoding()44 if has_likely_buggy_unicode_filesystem and not rv \45 or _is_ascii_encoding(rv):46 if not _warned_about_filesystem_encoding:47 warnings.warn(48 'Detected a misconfigured UNIX filesystem: Will use UTF-8 as '49 'filesystem encoding instead of {0!r}'.format(rv),50 BrokenFilesystemWarning)51 _warned_about_filesystem_encoding = True52 return 'utf-8'...

Full Screen

Full Screen

BUILD

Source:BUILD Github

copy

Full Screen

1# Experimental posix filesystem plugin.2load("//tensorflow:tensorflow.bzl", "tf_cc_shared_object")3package(4 default_visibility = ["//visibility:private"],5 licenses = ["notice"], # Apache 2.06)7# Filesystem implementation for POSIX environments: Linux, MacOS, Android, etc.8tf_cc_shared_object(9 name = "libposix_filesystem.so",10 framework_so = [],11 linkstatic = False,12 visibility = ["//visibility:public"],13 deps = [":posix_filesystem_impl"],14)15# The real implementation of the filesystem.16cc_library(17 name = "posix_filesystem_impl",18 srcs = ["posix_filesystem.cc"],19 hdrs = ["posix_filesystem.h"],20 deps = [21 ":posix_filesystem_helper",22 "//tensorflow/c:tf_status",23 "//tensorflow/c/experimental/filesystem:filesystem_interface",24 ],25)26# Since building pip package and API tests require a filesystem, we provide a27# static registration target that they should link against.28cc_library(29 name = "posix_filesystem_static",30 srcs = ["posix_filesystem_static.cc"],31 visibility = ["//visibility:public"],32 deps = [33 ":posix_filesystem_impl",34 "//tensorflow/c/experimental/filesystem:filesystem_interface",35 "//tensorflow/c/experimental/filesystem:modular_filesystem",36 ],37 alwayslink = 1,38)39# Library implementing helper functionality, so that the above only contains40# the API implementation for modular filesystems.41cc_library(42 name = "posix_filesystem_helper",43 srcs = ["posix_filesystem_helper.cc"],44 hdrs = ["posix_filesystem_helper.h"],45 deps = [":copy_file"],46)47# On Linux, we can copy files faster using `sendfile`. But not elsewhere.48# Hence, this private library to select which implementation to use.49cc_library(50 name = "copy_file",51 srcs = select({52 "//tensorflow:linux_x86_64": ["copy_file_linux.cc"],53 "//conditions:default": ["copy_file_portable.cc"],54 }),55 hdrs = ["copy_file.h"],...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1import { fileSystem } from 'ts-auto-mock/fileSystem';2import { createMock } from 'ts-auto-mock';3const fileSystemMock = fileSystem.createMock();4const mock = createMock<FileSystem>(fileSystemMock);5import { fileSystem } from 'ts-auto-mock/fileSystem';6import { createMock } from 'ts-auto-mock';7const fileSystemMock = fileSystem.createMock();8const mock = createMock<FileSystem>(fileSystemMock);9import { createMock } from 'ts-auto-mock';10const fileSystemMock = createMock<FileSystem>();11const mock = createMock<FileSystem>(fileSystemMock);12const fileSystemMock = createMock<FileSystem>(existingFileSystemMock);13const mock = createMock<FileSystem>(fileSystemMock);

Full Screen

Using AI Code Generation

copy

Full Screen

1import {fileSystem} from 'ts-auto-mock';2const mock: string = fileSystem.readFileSync('path/to/file.ts', 'utf8');3import {fileSystem} from 'ts-auto-mock';4const mock: string = fileSystem.readFileSync('path/to/file.ts', 'utf8');5import {fileSystem} from 'ts-auto-mock';6const mock: string = fileSystem.readFileSync('path/to/file.ts', 'utf8');

Full Screen

Using AI Code Generation

copy

Full Screen

1import { createMock } from 'ts-auto-mock';2const mock = createMock<FileSystem>();3import { createMock } from 'ts-auto-mock';4const mock = createMock<FileSystem>();5import { interface1, interface2 } from './interfaces';6const mock1 = createMock<interface1>();7const mock2 = createMock<interface2>();8const mock1 = createMock<interface1>('mock1');9const mock2 = createMock<interface2>('mock2');10const mock1 = createMock<interface1>('mock1');11const mock2 = createMock<interface2>('mock2');12const mock1 = createMock<interface1>('mock1');13const mock2 = createMock<interface2>('mock2');14const mock1 = createMock<interface1>('mock1');15const mock2 = createMock<interface2>('mock2');

Full Screen

Using AI Code Generation

copy

Full Screen

1import { fileSystem } from 'ts-auto-mock';2const file = fileSystem.getFile('test1.ts');3import { fileSystem } from 'ts-auto-mock';4const file = fileSystem.getFile('test2.ts');5import { fileSystem } from 'ts-auto-mock';6const file = fileSystem.getFile('test3.ts');7import { fileSystem } from 'ts-auto-mock';8const file = fileSystem.getFile('test4.ts');9import { fileSystem } from 'ts-auto-mock';10const file = fileSystem.getFile('test5.ts');11import { fileSystem } from 'ts-auto-mock';12const file = fileSystem.getFile('test6.ts');13import { fileSystem } from 'ts-auto-mock';14const file = fileSystem.getFile('test7.ts');15import { fileSystem } from 'ts-auto-mock';16const file = fileSystem.getFile('test8.ts');17import { fileSystem } from 'ts-auto-mock';18const file = fileSystem.getFile('test9.ts');

Full Screen

Using AI Code Generation

copy

Full Screen

1import {fileSystem} from 'ts-auto-mock';2import {myFunction} from './myFunction';3describe('myFunction', () => {4 it('should return the result of the function', () => {5 const mockFileSystem = fileSystem();6 mockFileSystem.addMockFile({7 content: 'export const fileContent = "mockContent";',8 });9 const mockModule = mockFileSystem.createMockModule('fileToImport.ts');10 const {fileContent} = mockModule.import();11 const spy = jest.spyOn(myFunction, 'myFunction');12 myFunction.myFunction();13 expect(spy).toHaveBeenCalledWith(fileContent);14 });15});

Full Screen

Using AI Code Generation

copy

Full Screen

1import * as fileSystem from 'ts-auto-mock/fileSystem';2fileSystem.setFileSystem({3 readFile: (path, encoding, callback) => {4 callback(null, 'test');5 },6});7import { myFunction } from './myFunction';8import * as fs from 'fs';9export function myFunction() {10 return fs.readFileSync('test.txt', 'utf8');11}

Full Screen

Using AI Code Generation

copy

Full Screen

1import {fileSystem} from 'ts-auto-mock/fileSystem';2fileSystem.writeFileSync('test2.ts', 'export interface Test2 {}');3import {Test2} from './test2';4const test2: Test2 = {5};6export interface Test2 {7 property: string;8}

Full Screen

Using AI Code Generation

copy

Full Screen

1import * as fileSystem from 'ts-auto-mock/fileSystem';2import { MyClass } from './myClass';3const myClass = new MyClass();4myClass.myMethod();5import { MyInterface } from './myInterface';6export class MyClass {7 public myMethod(): number {8 const myInterface: MyInterface = createMock<MyInterface>();9 return myInterface.myMethod();10 }11}12export interface MyInterface {13 myMethod(): number;14}15export const myInterface: MyInterface = {16 myMethod(): number {17 throw new Error('Not implemented');18 }19};20export const myClass: MyClass = {21 myMethod(): number {22 throw new Error('Not implemented');23 }24};25module.exports = {26};

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 ts-auto-mock 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