Best Python code snippet using localstack_python
test_path.py
Source:test_path.py
...47 shutil.rmtree(str(self.parent))48 def test_creating_file(self):49 file_path = self.parent / "test"50 assert not file_path.exists()51 created = path.get_or_create_file(str(file_path))52 assert file_path.is_file()53 assert created == file_path54 def test_creating_nested_file(self):55 level2_dir = self.parent / "test"56 file_path = self.parent / "test" / "test"57 assert not level2_dir.exists()58 assert not file_path.exists()59 created = path.get_or_create_file(str(file_path))60 assert level2_dir.is_dir()61 assert file_path.is_file()62 assert created == file_path63 def test_creating_existing_file(self):64 file_path = self.parent / "test"65 path.get_or_create_file(str(file_path))66 created = path.get_or_create_file(str(file_path))67 assert file_path.is_file()68 assert created == file_path69 def test_create_file_with_name_of_existing_dir_throws_error(self):70 with pytest.raises(OSError):71 path.get_or_create_file(self.parent)72 def test_create_file_with_none_filename_throws_type_error(self):73 with pytest.raises(TypeError):74 path.get_or_create_file(None)75 def test_create_dir_without_mkdir(self):76 file_path = self.parent / "foo" / "bar"77 with pytest.raises(OSError):78 path.get_or_create_file(file_path, mkdir=False)79 def test_create_dir_with_bytes_content(self):80 file_path = self.parent / "test"81 created = path.get_or_create_file(str(file_path), content=b"foobar")82 assert created.read_bytes() == b"foobar"83 def test_create_dir_with_unicode_content(self):84 file_path = self.parent / "test"85 created = path.get_or_create_file(str(file_path), content="foobaræøå")86 assert created.read_bytes() == b"foobar\xc3\xa6\xc3\xb8\xc3\xa5"87class GetUnixSocketPathTest(unittest.TestCase):88 def test_correctly_matched_socket_path(self):89 assert (90 path.get_unix_socket_path("unix:/tmp/mopidy.socket")91 == "/tmp/mopidy.socket"92 )93 def test_correctly_no_match_socket_path(self):94 assert path.get_unix_socket_path("127.0.0.1") is None95class PathToFileURITest(unittest.TestCase):96 def test_simple_path(self):97 result = path.path_to_uri("/etc/fstab")98 assert result == "file:///etc/fstab"99 def test_space_in_path(self):...
upload.py
Source:upload.py
...24 i = filename.rfind(".")25 if i != -1:26 filename = filename[0:i] + filename[i:].lower()27 return get_valid_filename(filename)28def get_or_create_file(chunk, dst):29 if chunk == 0:30 f = file(dst, 'wb')31 else:32 f = file(dst, 'ab')33 return f34def upload_with_checksum(request, dst, md5chunk, md5total, chunk, chunks):35 """Save application/octet-stream request to file.36 :param dst: the destination filepath37 :param chunk: the chunk number38 :param chunks: the total number of chunks39 :param md5chunk: md5sum of chunk40 :param md5total: md5sum of all currently sent chunks41 """42 buf_len = int(request.POST['chunk_size'])43 buf = request.body.read(buf_len)44 md5 = hashlib.md5()45 md5.update(buf)46 if md5.hexdigest() != md5chunk:47 raise BadRequest("Checksum error")48 f = get_or_create_file(chunk, dst)49 f.write(buf)50 f.close()51 52 f_meta = file(dst + '.meta', 'w') 53 write_meta_information_to_file(f_meta, md5total, chunk, chunks)54def upload_simple(request, dst, chunk=0):55 f = get_or_create_file(chunk, dst)56 file = request.FILES['file']57 for b in file:58 f.write(b)59 f.close()60 61if __name__ == '__main__':62 # in cgi environment63 import cgitb; cgitb.enable()...
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!!