Best Python code snippet using autotest_python
working_with_dir.py
Source:working_with_dir.py
1from utilities import (space, separated, start, end, sub, new_topic)2import os3from datetime import datetime4# Key5key = 'modules_os_dir_and_navigation'6def comeback():7 # goback to project working dir8 os.chdir('D:\\Programming\\Python\\Corey_Schafer_Tutorial')9def run():10 start('Modules and Packages')11 sub('Directory Management and Navigation')12 new_topic('dir() function')13 print(dir(os))14 new_topic('get current working dir with os.getcwd()', True)15 print(os.getcwd())16 new_topic('Navigate to new working directory os.chdir()', True)17 os.chdir('D:\\Programming\\Python')18 print(os.getcwd())19 # comeback to project working dir20 comeback()21 new_topic('List directory with os.listdir()', True)22 print(os.listdir())23 new_topic('Create a new directory with os.mkdir() and os.makedirs', True)24 # go to a temp foloder25 os.chdir('D:\\Temp\\Python')26 # os.mkdir will create the top level27 os.mkdir('dir1')28 # os.makedirs will be created both the top and its sub dirs immediately29 os.makedirs('dir2/sub_dir')30 print(f'current objs in the dir: {os.listdir()}')31 new_topic('Create a new directory with os.rmdir() and os.removedirs', True)32 # os.rmdir will delete only the top level33 os.rmdir('dir1')34 # os.removedirs will be deleted both the top and its sub dirs immediately35 os.removedirs('dir2/sub_dir')36 print(f'current objs in the dir: {os.listdir()}')37 # new_topic('Create a new file', True)38 new_topic('Rename a file with os.rename()', True)39 print(f'current objs in the dir: {os.listdir()}')40 # os.rename('test.txt', 'test_rename.txt')41 print(f'current objs in the dir: {os.listdir()}')42 new_topic('Check file stat with os.stat()', True)43 print(os.stat('test_rename.txt'))44 print(os.stat('test_rename.txt').st_size)45 print(f'modified at: {os.stat("test_rename.txt").st_mtime}')46 mod_time = os.stat('test_rename.txt').st_mtime47 print(f'modified at: {datetime.fromtimestamp(mod_time)}')48 new_topic('list all objects with os.walk()', True)49 current_dir = os.getcwd()50 # current path is the starting point51 for dirpath, dirnames, filenames in os.walk(current_dir):52 print('Current Path:', dirpath)53 print('Directories:', dirnames)54 print('Files', filenames)55 comeback()...
file_tests.py
Source:file_tests.py
...18 test_manual()19 test_dvk_html()20 test_sequencing()21 test_reformat()...
test_rename.py
Source:test_rename.py
1# Copyright 2012 Viewfinder Inc. All Rights Reserved.2"""Test object for the TEST_RENAME database testing table.3"""4__author__ = 'andy@emailscrubbed.com (Andy Kimball)'5from viewfinder.backend.db import vf_schema6from viewfinder.backend.db.base import DBObject7from viewfinder.backend.db.range_base import DBRangeObject8@DBObject.map_table_attributes9class TestRename(DBRangeObject):10 """Used for testing."""11 __slots__ = []...
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!