How to use get_relative_path method in autotest

Best Python code snippet using autotest_python

test_snapshot.py

Source:test_snapshot.py Github

copy

Full Screen

...27 assert len(diff.dirs_deleted) == 028 assert len(diff.files_created) == 029 assert len(diff.files_deleted) == 030 assert len(diff.files_modified) == 031 assert get_relative_path(source, diff.dirs_created[0]) == "foo"32def test_delete_dir():33 with temporary_directory() as source:34 (Path(source) / "foo").mkdir()35 snapshot1 = DirectorySnapshot(source)36 os.rmdir(Path(source) / "foo")37 snapshot2 = DirectorySnapshot(source)38 diff = compute_snapshot_diff(ref=snapshot1, snapshot=snapshot2)39 assert len(diff.dirs_created) == 040 assert len(diff.dirs_deleted) == 141 assert len(diff.files_created) == 042 assert len(diff.files_deleted) == 043 assert len(diff.files_modified) == 044 assert get_relative_path(source, diff.dirs_deleted[0]) == "foo"45def test_move_dir():46 with temporary_directory() as source:47 (Path(source) / "foo").mkdir()48 snapshot1 = DirectorySnapshot(source)49 os.rename((Path(source) / "foo"), (Path(source) / "foo2"))50 snapshot2 = DirectorySnapshot(source)51 diff = compute_snapshot_diff(ref=snapshot1, snapshot=snapshot2)52 assert len(diff.dirs_created) == 153 assert len(diff.dirs_deleted) == 154 assert len(diff.files_created) == 055 assert len(diff.files_deleted) == 056 assert len(diff.files_modified) == 057 assert get_relative_path(source, diff.dirs_deleted[0]) == "foo"58 assert get_relative_path(source, diff.dirs_created[0]) == "foo2"59def test_create_file():60 with temporary_directory() as source:61 snapshot1 = DirectorySnapshot(source)62 (Path(source) / "foo").touch()63 snapshot2 = DirectorySnapshot(source)64 diff = compute_snapshot_diff(ref=snapshot1, snapshot=snapshot2)65 assert len(diff.dirs_created) == 066 assert len(diff.dirs_deleted) == 067 assert len(diff.files_created) == 168 assert len(diff.files_deleted) == 069 assert len(diff.files_modified) == 070 assert get_relative_path(source, diff.files_created[0]) == "foo"71def test_delete_file():72 with temporary_directory() as source:73 (Path(source) / "foo").touch()74 snapshot1 = DirectorySnapshot(source)75 os.remove(Path(source) / "foo")76 snapshot2 = DirectorySnapshot(source)77 diff = compute_snapshot_diff(ref=snapshot1, snapshot=snapshot2)78 assert len(diff.dirs_created) == 079 assert len(diff.dirs_deleted) == 080 assert len(diff.files_created) == 081 assert len(diff.files_deleted) == 182 assert len(diff.files_modified) == 083 assert get_relative_path(source, diff.files_deleted[0]) == "foo"84def test_modify_file():85 with temporary_directory() as source:86 (Path(source) / "foo").touch()87 snapshot1 = DirectorySnapshot(source)88 with open(Path(source) / "foo", "w") as f:89 f.write("blah")90 snapshot2 = DirectorySnapshot(source)91 diff = compute_snapshot_diff(ref=snapshot1, snapshot=snapshot2)92 assert len(diff.dirs_created) == 093 assert len(diff.dirs_deleted) == 094 assert len(diff.files_created) == 095 assert len(diff.files_deleted) == 096 assert len(diff.files_modified) == 197 assert get_relative_path(source, diff.files_modified[0]) == "foo"98def test_move_file():99 with temporary_directory() as source:100 (Path(source) / "foo").touch()101 snapshot1 = DirectorySnapshot(source)102 os.rename((Path(source) / "foo"), (Path(source) / "foo2"))103 snapshot2 = DirectorySnapshot(source)104 diff = compute_snapshot_diff(ref=snapshot1, snapshot=snapshot2)105 assert len(diff.dirs_created) == 0106 assert len(diff.dirs_deleted) == 0107 assert len(diff.files_created) == 1108 assert len(diff.files_deleted) == 1109 assert len(diff.files_modified) == 0110 assert get_relative_path(source, diff.files_deleted[0]) == "foo"111 assert get_relative_path(source, diff.files_created[0]) == "foo2"112def test_create_dir_with_file():113 with temporary_directory() as source:114 snapshot1 = DirectorySnapshot(source)115 (Path(source) / "foo").mkdir()116 (Path(source) / "foo" / "bar").touch()117 snapshot2 = DirectorySnapshot(source)118 diff = compute_snapshot_diff(ref=snapshot1, snapshot=snapshot2)119 assert len(diff.dirs_created) == 1120 assert len(diff.dirs_deleted) == 0121 assert len(diff.files_created) == 1122 assert len(diff.files_deleted) == 0123 assert len(diff.files_modified) == 0124 assert get_relative_path(source, diff.dirs_created[0]) == "foo"125 assert Path(get_relative_path(source, diff.files_created[0])).as_posix() == "foo/bar"126def test_move_dir_with_file():127 with temporary_directory() as source:128 (Path(source) / "foo").mkdir()129 (Path(source) / "foo" / "bar").touch()130 snapshot1 = DirectorySnapshot(source)131 os.rename((Path(source) / "foo"), (Path(source) / "foo2"))132 snapshot2 = DirectorySnapshot(source)133 diff = compute_snapshot_diff(ref=snapshot1, snapshot=snapshot2)134 assert len(diff.dirs_created) == 1135 assert len(diff.dirs_deleted) == 1136 assert len(diff.files_created) == 1137 assert len(diff.files_deleted) == 1138 assert len(diff.files_modified) == 0139 assert get_relative_path(source, diff.dirs_deleted[0]) == "foo"140 assert get_relative_path(source, diff.dirs_created[0]) == "foo2"141 assert Path(get_relative_path(source, diff.files_deleted[0])).as_posix() == "foo/bar"142 assert Path(get_relative_path(source, diff.files_created[0])).as_posix() == "foo2/bar"143def test_delete_dir_with_file():144 with temporary_directory() as source:145 (Path(source) / "foo").mkdir()146 (Path(source) / "foo" / "bar").touch()147 snapshot1 = DirectorySnapshot(source)148 shutil.rmtree(Path(source) / "foo")149 snapshot2 = DirectorySnapshot(source)150 diff = compute_snapshot_diff(ref=snapshot1, snapshot=snapshot2)151 assert len(diff.dirs_created) == 0152 assert len(diff.dirs_deleted) == 1153 assert len(diff.files_created) == 0154 assert len(diff.files_deleted) == 1155 assert len(diff.files_modified) == 0156 assert get_relative_path(source, diff.dirs_deleted[0]) == "foo"157 assert Path(get_relative_path(source, diff.files_deleted[0])).as_posix() == "foo/bar"158def test_replace_dir_with_file():159 with temporary_directory() as source:160 (Path(source) / "foo").mkdir()161 snapshot1 = DirectorySnapshot(source)162 os.rmdir(Path(source) / "foo")163 (Path(source) / "foo").touch()164 snapshot2 = DirectorySnapshot(source)165 diff = compute_snapshot_diff(ref=snapshot1, snapshot=snapshot2)166 assert len(diff.dirs_created) == 0167 assert len(diff.dirs_deleted) == 1168 assert len(diff.files_created) == 1169 assert len(diff.files_deleted) == 0170 assert len(diff.files_modified) == 0171 assert get_relative_path(source, diff.dirs_deleted[0]) == "foo"172 assert get_relative_path(source, diff.files_created[0]) == "foo"173def test_replace_file_with_dir():174 with temporary_directory() as source:175 (Path(source) / "foo").touch()176 snapshot1 = DirectorySnapshot(source)177 os.remove(Path(source) / "foo")178 (Path(source) / "foo").mkdir()179 snapshot2 = DirectorySnapshot(source)180 diff = compute_snapshot_diff(ref=snapshot1, snapshot=snapshot2)181 assert len(diff.dirs_created) == 1182 assert len(diff.dirs_deleted) == 0183 assert len(diff.files_created) == 0184 assert len(diff.files_deleted) == 1185 assert len(diff.files_modified) == 0186 assert get_relative_path(source, diff.dirs_created[0]) == "foo"...

Full Screen

Full Screen

thread_edit_log_worker.py

Source:thread_edit_log_worker.py Github

copy

Full Screen

...81 return True82 else:83 return false84 85 def get_relative_path(self, path):86 rPath = "." + path;87 return rPath;88 89 def getattr(self, path, fh=None): 90 rpath = self.get_relative_path(path)91 g.debug_log.log("At getattr for " + rpath)92 93 try: 94 st = os.lstat(rpath)95 96 # print "After getattr for " + rpath97 g.debug_log.log("After getattr for " + rpath)98 99 ret = dict((key, getattr(st, key)) for key in ('st_atime', 'st_ctime',100 'st_gid', 'st_mode', 'st_mtime', 'st_nlink', 'st_size', 'st_uid'))101 102 #for key in ('st_atime', 'st_ctime', 'st_gid', 'st_mode', 'st_mtime', 'st_nlink', 'st_size', 'st_uid'):103 # print key + ":" + str(getattr(st, key))104 105 return ret106 107 except:108 109 raise FuseOSError(ENOENT)110 111 def statfs(self, path):112 rpath = self.get_relative_path(path)113 114 # print "At statfs"115 g.debug_log.log("At statfs")116 stv = os.statvfs(rpath)117 return dict((key, getattr(stv, key)) for key in ('f_bavail', 'f_bfree',118 'f_blocks', 'f_bsize', 'f_favail', 'f_ffree', 'f_files', 'f_flag',119 'f_frsize', 'f_namemax'))120 def create(self, path, mode): 121 rpath = self.get_relative_path(path)122 123 # print "At create"124 g.debug_log.log("At create")125 ret = os.open(rpath, os.O_WRONLY | os.O_CREAT, mode)126 127 # print "After create, ret: " + str(ret)128 g.debug_log.log("After create, ret: " + str(ret))129 130 return ret131 def access(self, path, mode):132 133 rpath = self.get_relative_path(path)134 135 ret = os.access(rpath, mode)136 137 g.debug_log.log("At access " + rpath + ", mode: " + str(mode) + ", ret:" + str(ret))138 139 if not ret:140 raise FuseOSError(EACCES)141 142 def mkdir(self, path, mode):143 144 rpath = self.get_relative_path(path)145 146 147 #print "At mkdir"148 149 return os.mkdir(rpath, mode)150 151 def mknod(self, path, mode, dev):152 153 rpath = self.get_relative_path(path)154 #print "At mknod"155 return os.mknod(rpath, mode, dev)156 157 def open(self, path, flags):158 rpath = self.get_relative_path(path)159 #print "At open"160 return os.open(rpath, flags)161 162 163 def readlink(self, path):164 rpath = self.get_relative_path(path)165 166 167 #print "At readlink"168 return os.readlink(rpath)169 170 def unlink(self, path):171 172 rpath = self.get_relative_path(path)173 174 175 #print "At unlink"176 return os.unlink(rpath)177 178 def utimens(self, path, times=None):179 rpath = self.get_relative_path(path)180 181 182 #print "At utimens"183 184 return os.utime(rpath, times)185 def utime(self, path, times=None):186 rpath = self.get_relative_path(path)187 188 189 #print "At utime"190 191 return os.utime(rpath, times)192 193 def rmdir(self, path):194 rpath = self.get_relative_path(path)195 196 197 #print "At rmdir"198 199 return os.rmdir(rpath)200 201 def symlink(self, target, source):202 203 204 #print "At symlink"205 206 rtarget = self.get_relative_path(target)207 208 return os.symlink(source, rtarget)209 210 def rename(self, old, new):211 rold = self.get_relative_path(old)212 rnew = self.get_relative_path(new)213 214 215 #print "At rename, rename " + str(rold) + " to " + str(rnew)216 217 218 219 return os.rename(rold, rnew)220 221 def link(self, target, source):222 rtarget = self.get_relative_path(target)223 rsource = self.get_relative_path(source)224 225 226 #print "At link"227 228 return os.link(rsource, rtarget)229 230 def chmod(self, path, mode):231 rpath = self.get_relative_path(path)232 #print "At chmod"233 return os.chmod(rpath, mode)234 235 def chown(self, path, uid, gid):236 rpath = self.get_relative_path(path)237 #print "At chown"238 return os.chown(rpath, uid, gid)239 240 listxattr = None241 242 243 244 def flush(self, path, fh):245 246 247 #print "At flush"248 249 return os.fsync(fh)250 def fsync(self, path, datasync, fh):251 252 253 #print "At fsync"254 255 return os.fsync(fh)256 def truncate(self, path, length, fh=None):257 rpath = self.get_relative_path(path)258 #print "At truncate for file " + str(rpath)259 f = os.open(rpath, os.O_RDWR)260 return os.ftruncate(f, length)261 def read(self, path, size, offset, fh):262 263 #print "At read"264 265 with self.rwlock:266 os.lseek(fh, offset, 0)267 return os.read(fh, size)268 def readdir(self, path, fh):269 270 #print "At readdir"271 272 rpath = self.get_relative_path(path)273 return ['.', '..'] + os.listdir(rpath)274 275 def release(self, path, fh):276 277 #print "At release for path " + str(path)278 279 return os.close(fh)280 281 def write(self, path, data, offset, fh):282 rpath = self.get_relative_path(path)283 #print "At write"284 with self.rwlock:285 os.lseek(fh, offset, 0)286 g.debug_log.log("write at offset " + str(offset) + " for file " + str(rpath))287 288 if not self.msg_queue is None:289 g.debug_log.log("Start sending data to main thread")290 self.msg_queue.put(data)291 292 return os.write(fh, data)293if __name__ == "__main__":294 if len(argv) != 2:295 print 'usage: %s <mountpoint>' % argv[0]296 exit(1)...

Full Screen

Full Screen

index.py

Source:index.py Github

copy

Full Screen

...20 children=[21 ddk.Header(22 children=[23 dcc.Link(24 href=app.get_relative_path("/"),25 children=[ddk.Logo(src=app.get_relative_path("/assets/hnts.png"))],26 ),27 ddk.Title("Daily Standup"),28 html.Div(29 [30 html.P(31 "Powered by",32 style={"float": "left", 'fontSize': 10, "margin-bottom":"0px"},33 ),34 html.Img(35 src=app.get_asset_url("his.png"),36 style={37 "width": "130px",38 "float": "left",39 "margin-top": "0px",40 "margin-left": "5px"41 }42 )43 ]44 ),45 ],46 style={"backgroundColor": "var(--accent_positive)"}47 ),48 ddk.Sidebar([49 ddk.Menu([50 dcc.Link(51 href=app.get_relative_path('/'),52 children='Home'53 ),54 dcc.Link(55 href=app.get_relative_path('/census'),56 children='Census'57 ),58 dcc.Link(59 href=app.get_relative_path('/VisitPlanning'),60 children='VisitPlanning'61 ),62 dcc.Link(63 href=app.get_relative_path('/orders'),64 children='Orders'65 ),66 dcc.Link(67 href=app.get_relative_path('/authorizations'),68 children='Authorizations'69 ),70 dcc.Link(71 href=app.get_relative_path('/bd'),72 children='Business Development'73 ),74 dcc.Link(75 href=app.get_relative_path('/qa'),76 children='Quality Assurance'77 ),78 dcc.Link(79 href=app.get_relative_path('/billing'),80 children='Billing'81 ),82 dcc.Link(83 href=app.get_relative_path('/OrderProcessing'),84 children='Order Processing'85 ),86 ]),87 ]),88 dcc.Location(id='url', refresh=False),89 ddk.SidebarCompanion(html.Div(id='content'))90 ],91 show_editor=True 92)93@app.callback(94 Output("content", "children"), [Input("url", "pathname")], prevent_initial_call=True95)96def display_content(pathname):97 page_name = app.strip_relative_path(pathname)...

Full Screen

Full Screen

test_esd_filehandler.py

Source:test_esd_filehandler.py Github

copy

Full Screen

1# coding=utf-82# Copyright (c) 2017,2018, F5 Networks, Inc.3#4# Licensed under the Apache License, Version 2.0 (the "License");5# you may not use this file except in compliance with the License.6# You may obtain a copy of the License at7#8# http://www.apache.org/licenses/LICENSE-2.09#10# Unless required by applicable law or agreed to in writing, software11# distributed under the License is distributed on an "AS IS" BASIS,12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.13# See the License for the specific language governing permissions and14# limitations under the License.15#16import pytest17from f5_openstack_agent.lbaasv2.drivers.bigip.esd_filehandler import \18 EsdJSONValidation19from f5_openstack_agent.lbaasv2.drivers.bigip import exceptions as f5_ex20class TestEsdFileHanlder(object):21 remaining_path = 'f5_openstack_agent/lbaasv2/drivers/bigip/test/json'22 @staticmethod23 def assertEqual(obj1, obj2, note=''):24 assert obj1 == obj2, note25 @staticmethod26 def assertRaises(exc):27 return pytest.raises(exc)28 @staticmethod29 def assertIn(obj1, dict_obj, note=''):30 assert obj1 in dict_obj, note31 def test_invalid_dir_name(self):32 # invliad directory name33 reader = EsdJSONValidation('/as87awoiujasdf/')34 assert not reader.esdJSONFileList35 def test_no_files(self, get_relative_path):36 # verify no files in empty directory37 reader = EsdJSONValidation(38 '{}/{}/empty_dir'.format(get_relative_path, self.remaining_path))39 assert not reader.esdJSONFileList40 def test_no_json_files(self, get_relative_path):41 # verify no files are read in dir that contains non-JSON files42 reader = EsdJSONValidation(43 '{}/{}/no_json'.format(get_relative_path, self.remaining_path))44 assert not reader.esdJSONFileList45 def test_mix_json_files(self, get_relative_path):46 # verify single JSON file47 reader = EsdJSONValidation(48 '{}/{}/mix_json/'.format(get_relative_path, self.remaining_path))49 self.assertEqual(1, len(reader.esdJSONFileList))50 def test_json_only_files(self, get_relative_path):51 # expect three files52 reader = EsdJSONValidation(53 '{}/{}/valid'.format(get_relative_path, self.remaining_path))54 self.assertEqual(3, len(reader.esdJSONFileList))55 def test_invalid_json(self, get_relative_path):56 handler = EsdJSONValidation(57 '{}/{}/invalid'.format(get_relative_path, self.remaining_path))58 # verify exception raised59 with self.assertRaises(f5_ex.esdJSONFileInvalidException):60 handler.read_json()61 def test_valid_json(self, get_relative_path):62 handler = EsdJSONValidation(63 '{}/{}/valid/'.format(get_relative_path, self.remaining_path))64 dict = handler.read_json()65 # verify keys in the final dictionary66 self.assertIn('app_type_1', dict)67 self.assertIn('app_type_2', dict)68 self.assertIn('app_type_3', dict)69 def test_empty_json(self, get_relative_path):70 # verify empty file is read71 handler = EsdJSONValidation(72 '{}/{}/empty_file/'.format(get_relative_path, self.remaining_path))73 self.assertEqual(1, len(handler.esdJSONFileList))74 # verify empty dict is returned75 dict = handler.read_json()...

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