Best Python code snippet using autotest_python
test_fs_symlink_loops.py
Source:test_fs_symlink_loops.py
1#******************************************************************************2# (C) 2013 Ableton AG3#******************************************************************************4import os5import tempfile6import stat7from unittest import TestCase8import shutil9from abl.vpath.base import URI10from .common import (11 create_file,12 load_file,13 is_on_mac,14 CleanupMemoryBeforeTestMixin,15)16#-------------------------------------------------------------------------------17class CommonLocalFSSymlinkLoopTest(TestCase):18 __test__ = False19 def test_selfpointing_symlink(self):20 root = URI(self.baseurl)21 tee_path = root / 'helloworld'22 tee_path.symlink(tee_path)23 self.assertTrue(tee_path.islink())24 self.assertEqual(tee_path.readlink(), tee_path)25 def test_listdir_fails_on_selfpointing_symlink(self):26 root = URI(self.baseurl)27 tee_path = root / 'helloworld'28 tee_path.symlink(tee_path)29 self.assertRaises(OSError, tee_path.listdir)30 def test_open_fails_on_selfpointing_symlink(self):31 root = URI(self.baseurl)32 tee_path = root / 'helloworld'33 tee_path.symlink(tee_path)34 self.assertRaises(IOError, load_file, tee_path)35 self.assertRaises(IOError, create_file, tee_path)36 def test_isexec_fails_on_selfpointing_symlink(self):37 root = URI(self.baseurl)38 tee_path = root / 'helloworld'39 tee_path.symlink(tee_path)40 self.assertRaises(OSError, tee_path.isexec)41 def test_set_exec_fails_on_selfpointing_symlink(self):42 root = URI(self.baseurl)43 tee_path = root / 'helloworld'44 tee_path.symlink(tee_path)45 self.assertRaises(OSError, tee_path.set_exec, stat.S_IXUSR | stat.S_IXGRP)46 def test_remove_fails_on_selfpointing_symlink(self):47 root = URI(self.baseurl)48 tee_path = root / 'helloworld'49 tee_path.symlink(tee_path)50 self.assertTrue(tee_path.islink())51 tee_path.remove()52 self.assertTrue(not tee_path.islink())53 self.assertTrue(not tee_path.exists())54 def test_copystat_fails_on_selfpointing_symlink(self):55 root = URI(self.baseurl)56 bar_path = root / 'gaz.txt'57 create_file(bar_path)58 tee_path = root / 'helloworld'59 tee_path.symlink(tee_path)60 self.assertRaises(OSError, bar_path.copystat, tee_path)61 self.assertRaises(OSError, tee_path.copystat, bar_path)62 def test_isdir_doesnt_fail_on_selfpointing_symlink(self):63 root = URI(self.baseurl)64 tee_path = root / 'helloworld'65 tee_path.symlink(tee_path)66 self.assertTrue(not tee_path.isdir())67 def test_isfile_doesnt_fail_on_selfpointing_symlink(self):68 root = URI(self.baseurl)69 tee_path = root / 'helloworld'70 tee_path.symlink(tee_path)71 self.assertTrue(not tee_path.isfile())72 def test_exists_doesnt_fail_on_selfpointing_symlink(self):73 root = URI(self.baseurl)74 tee_path = root / 'helloworld'75 tee_path.symlink(tee_path)76 self.assertTrue(not tee_path.exists())77 #------------------------------78 def test_symlink_loop(self):79 root = URI(self.baseurl)80 foo_path = root / 'foo'81 bar_path = foo_path / 'foo'82 bar_path.makedirs()83 tee_path = bar_path / 'tee'84 foo_path.symlink(tee_path)85 self.assertTrue(tee_path.islink())86 self.assertEqual(tee_path.readlink(), foo_path)87 def test_listdir_doesnt_fail_on_symlink_loop(self):88 root = URI(self.baseurl)89 foo_path = root / 'foo'90 bar_path = foo_path / 'foo' / 'bar'91 bar_path.makedirs()92 tee_path = bar_path / 'tee'93 foo_path.symlink(tee_path)94 moo_path = foo_path / 'moo.txt'95 create_file(moo_path)96 self.assertTrue('moo.txt' in tee_path.listdir())97 def test_open_fails_on_symlink_loop(self):98 root = URI(self.baseurl)99 tee_path = root / 'helloworld'100 tee_path.symlink(tee_path)101 self.assertRaises(IOError, load_file, tee_path)102 self.assertRaises(IOError, create_file, tee_path)103 def test_isexec_fails_on_symlink_loop(self):104 root = URI(self.baseurl)105 tee_path = root / 'helloworld'106 tee_path.symlink(tee_path)107 self.assertRaises(OSError, tee_path.isexec)108 def test_set_exec_fails_on_symlink_loop(self):109 root = URI(self.baseurl)110 tee_path = root / 'helloworld'111 tee_path.symlink(tee_path)112 self.assertRaises(OSError, tee_path.set_exec, stat.S_IXUSR | stat.S_IXGRP)113 def test_remove_doesnt_fail_on_symlink_loop(self):114 root = URI(self.baseurl)115 tee_path = root / 'helloworld'116 tee_path.makedirs()117 foo_path = tee_path / 'foo'118 tee_path.symlink(foo_path)119 tee_path.remove(recursive=True)120 self.assertTrue(not tee_path.exists())121 def test_copystat_fails_on_symlink_loop(self):122 root = URI(self.baseurl)123 bar_path = root / 'gaz.txt'124 create_file(bar_path)125 tee_path = root / 'helloworld'126 tee_path.symlink(tee_path)127 self.assertRaises(OSError, bar_path.copystat, tee_path)128 self.assertRaises(OSError, tee_path.copystat, bar_path)129 def test_filechecks_dont_fail_on_mutual_symlinks(self):130 root = URI(self.baseurl)131 tee_path = root / 'helloworld'132 foo_path = root / 'foo'133 tee_path.symlink(foo_path)134 foo_path.symlink(tee_path)135 self.assertTrue(not foo_path.isdir())136 self.assertTrue(not foo_path.isfile())137 self.assertTrue(not foo_path.exists())138 self.assertTrue(foo_path.islink())139 def test_remove_doesnt_fail_on_mutual_symlinks(self):140 root = URI(self.baseurl)141 tee_path = root / 'helloworld'142 foo_path = root / 'foo'143 foo_path.symlink(tee_path)144 tee_path.symlink(foo_path)145 tee_path.remove(recursive=True)146 self.assertTrue(not tee_path.exists())147 self.assertTrue(foo_path.islink())148class TestLocalFSSymlinkLoop(CommonLocalFSSymlinkLoopTest):149 __test__ = is_on_mac()150 def setUp(self):151 self.thisdir = os.path.split(os.path.abspath(__file__))[0]152 self.tmpdir = tempfile.mkdtemp('.temp', 'test-local-fs', self.thisdir)153 self.baseurl = 'file://' + self.tmpdir154 def tearDown(self):155 shutil.rmtree(self.tmpdir)156class TestMemoryFSSymlinkLoop(CleanupMemoryBeforeTestMixin, CommonLocalFSSymlinkLoopTest):157 __test__ = True158 def setUp(self):159 super(TestMemoryFSSymlinkLoop, self).setUp()160 self.baseurl = "memory:///"161 def tearDown(self):...
test_pipeline.py
Source:test_pipeline.py
...10 def test_adder(self):11 src, adder, sink = SampleSrc(sample=[1, 2, 3]), Adder(amount=1), StoreSink()12 Pipeline().connect_many(src, adder, sink).execute()13 self.assertEqual(sink.packets, [2, 3, 4])14 def test_false_tee(self):15 src, tee, sink = SampleSrc(sample=[1, 2, 3]), Tee(1), StoreSink()16 pipe = Pipeline().connect(src, tee)17 pipe.connect(tee, sink, 'tee_00', 'default').execute()18 self.assertEqual(sink.packets, [1, 2, 3])19 def test_tee(self):20 pipe = Pipeline()21 src = SampleSrc(sample=[1, 2, 3])22 tee = Tee(n_outputs=2)23 adder = Adder(amount=2)24 sink1, sink2 = StoreSink(), StoreSink()25 pipe.connect(src, tee)26 pipe.connect(tee, sink1, 'tee_00', 'default')27 pipe.connect(tee, adder, 'tee_01', 'default')28 pipe.connect(adder, sink2)29 #30 # Check write connections31 #32 # src -> tee33 src_to_tee = pipe.get_write_queue(src)...
main.py
Source:main.py
1# https://www.kaggle.com/wolfram77/puzzlef-pagerank-cuda-adjust-tolerance-function2import os3from IPython.display import FileLink4src="pagerank-cuda-adjust-tolerance-function"5inp="/kaggle/input/graphs"6out="{}.txt".format(src)7!printf "" > "$out"8display(FileLink(out))9!ulimit -s unlimited && echo ""10!nvidia-smi && echo ""11# Download program12!rm -rf $src13!git clone https://github.com/puzzlef/$src14!echo ""15# Run16!nvcc -std=c++17 -Xcompiler -DNVGRAPH_DISABLE -O3 $src/main.cu17!stdbuf --output=L ./a.out $inp/min-1DeadEnd.mtx 2>&1 | tee -a "$out"18!stdbuf --output=L ./a.out $inp/min-2SCC.mtx 2>&1 | tee -a "$out"19!stdbuf --output=L ./a.out $inp/min-4SCC.mtx 2>&1 | tee -a "$out"20!stdbuf --output=L ./a.out $inp/min-NvgraphEx.mtx 2>&1 | tee -a "$out"21!stdbuf --output=L ./a.out $inp/web-Stanford.mtx 2>&1 | tee -a "$out"22!stdbuf --output=L ./a.out $inp/web-BerkStan.mtx 2>&1 | tee -a "$out"23!stdbuf --output=L ./a.out $inp/web-Google.mtx 2>&1 | tee -a "$out"24!stdbuf --output=L ./a.out $inp/web-NotreDame.mtx 2>&1 | tee -a "$out"25!stdbuf --output=L ./a.out $inp/soc-Slashdot0811.mtx 2>&1 | tee -a "$out"26!stdbuf --output=L ./a.out $inp/soc-Slashdot0902.mtx 2>&1 | tee -a "$out"27!stdbuf --output=L ./a.out $inp/soc-Epinions1.mtx 2>&1 | tee -a "$out"28!stdbuf --output=L ./a.out $inp/coAuthorsDBLP.mtx 2>&1 | tee -a "$out"29!stdbuf --output=L ./a.out $inp/coAuthorsCiteseer.mtx 2>&1 | tee -a "$out"30!stdbuf --output=L ./a.out $inp/soc-LiveJournal1.mtx 2>&1 | tee -a "$out"31!stdbuf --output=L ./a.out $inp/coPapersCiteseer.mtx 2>&1 | tee -a "$out"32!stdbuf --output=L ./a.out $inp/coPapersDBLP.mtx 2>&1 | tee -a "$out"33!stdbuf --output=L ./a.out $inp/indochina-2004.mtx 2>&1 | tee -a "$out"34!stdbuf --output=L ./a.out $inp/italy_osm.mtx 2>&1 | tee -a "$out"35!stdbuf --output=L ./a.out $inp/great-britain_osm.mtx 2>&1 | tee -a "$out"36!stdbuf --output=L ./a.out $inp/germany_osm.mtx 2>&1 | tee -a "$out"...
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!!