Best Python code snippet using fMBT_python
test_tarfile.py
Source:test_tarfile.py
...795 def _add_testfile(self, fileobj=None):796 tar = tarfile.open(self.tarname, "a", fileobj=fileobj)797 tar.addfile(tarfile.TarInfo("bar"))798 tar.close()799 def _create_testtar(self, mode="w:"):800 src = tarfile.open(tarname, encoding="iso8859-1")801 t = src.getmember("ustar/regtype")802 t.name = "foo"803 f = src.extractfile(t)804 tar = tarfile.open(self.tarname, mode)805 tar.addfile(t, f)806 tar.close()807 def _test(self, names=["bar"], fileobj=None):808 tar = tarfile.open(self.tarname, fileobj=fileobj)809 self.assertEqual(tar.getnames(), names)810 def test_non_existing(self):811 self._add_testfile()812 self._test()813 def test_empty(self):814 open(self.tarname, "w").close()815 self._add_testfile()816 self._test()817 def test_empty_fileobj(self):818 fobj = StringIO.StringIO()819 self._add_testfile(fobj)820 fobj.seek(0)821 self._test(fileobj=fobj)822 def test_fileobj(self):823 self._create_testtar()824 data = open(self.tarname).read()825 fobj = StringIO.StringIO(data)826 self._add_testfile(fobj)827 fobj.seek(0)828 self._test(names=["foo", "bar"], fileobj=fobj)829 def test_existing(self):830 self._create_testtar()831 self._add_testfile()832 self._test(names=["foo", "bar"])833 def test_append_gz(self):834 if gzip is None:835 return836 self._create_testtar("w:gz")837 self.assertRaises(tarfile.ReadError, tarfile.open, tmpname, "a")838 def test_append_bz2(self):839 if bz2 is None:840 return841 self._create_testtar("w:bz2")842 self.assertRaises(tarfile.ReadError, tarfile.open, tmpname, "a")843class LimitsTest(unittest.TestCase):844 def test_ustar_limits(self):845 # 100 char name846 tarinfo = tarfile.TarInfo("0123456789" * 10)847 tarinfo.tobuf(tarfile.USTAR_FORMAT)848 # 101 char name that cannot be stored849 tarinfo = tarfile.TarInfo("0123456789" * 10 + "0")850 self.assertRaises(ValueError, tarinfo.tobuf, tarfile.USTAR_FORMAT)851 # 256 char name with a slash at pos 156852 tarinfo = tarfile.TarInfo("123/" * 62 + "longname")853 tarinfo.tobuf(tarfile.USTAR_FORMAT)854 # 256 char name that cannot be stored855 tarinfo = tarfile.TarInfo("1234567/" * 31 + "longname")...
BUILD
Source:BUILD
...61 "usr/titi",62 ],63 cmd = "for i in $(OUTS); do echo 1 >$$i; done",64)65[pkg_tar(66 name = "test-tar-%s" % ext[1:],67 extension = "tar%s" % ext,68 files = [69 ":etc/nsswitch.conf",70 ":usr/titi",71 ],72 mode = "0644",73 modes = {"usr/titi": "0755"},74 package_dir = "/",75 strip_prefix = ".",76 symlinks = {"usr/bin/java": "/path/to/bin/java"},77) for ext in [78 "",79 ".gz",80 ".bz2",81 ".xz", # This will breaks if xzcat is not installed82]]83[pkg_tar(84 name = "test-tar-inclusion-%s" % ext,85 deps = [":test-tar-%s" % ext],86) for ext in [87 "",88 "gz",89 "bz2",90 "xz",91]]92pkg_tar(93 name = "test-tar-strip_prefix-empty",94 files = [95 ":etc/nsswitch.conf",96 ],97 strip_prefix = "",98)99pkg_tar(100 name = "test-tar-strip_prefix-none",101 files = [102 ":etc/nsswitch.conf",103 ],104)105pkg_tar(106 name = "test-tar-strip_prefix-etc",107 files = [108 ":etc/nsswitch.conf",109 ],110 strip_prefix = "etc",111)112pkg_tar(113 name = "test-tar-strip_prefix-dot",114 files = [115 ":etc/nsswitch.conf",116 ],117 strip_prefix = ".",118)119pkg_deb(120 name = "test-deb",121 data = ":test-tar-gz.tar.gz",122 depends = [123 "dep1",124 "dep2",125 ],126 description = "toto",...
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!!