How to use test_replace_in_file method in localstack

Best Python code snippet using localstack_python

test_push_button.py

Source:test_push_button.py Github

copy

Full Screen

1import unittest2import os3import push_button4class TestPushButton(unittest.TestCase):5 def test_replace_in_file_present(self):6 with open("test_replace_in_file.txt", "w+") as write_file:7 write_file.write("Hello World")8 write_file.flush()9 push_button.replace_in_file("test_replace_in_file.txt", "Hello", "Hi")10 with open("test_replace_in_file.txt", "r") as read_file:11 self.assertEqual(read_file.readlines(), ["Hi World"])12 os.remove("test_replace_in_file.txt")13 def test_replace_in_file_absent(self):14 with open("test_replace_in_file.txt", "w+") as write_file:15 write_file.write("Hello World")16 write_file.flush()17 push_button.replace_in_file("test_replace_in_file.txt", "123", "Hi")18 with open("test_replace_in_file.txt", "r") as read_file:19 self.assertEqual(read_file.readlines(), ["Hello World"])20 os.remove("test_replace_in_file.txt")21 def test_get_display_name(self):22 self.assertEqual(push_button.get_display_name("username", 1), "\U0001F7E9 (1) username")23 def test_get_score_zero(self):24 self.assertEqual(push_button.get_score(60, 0), 0)25 def test_get_score_one(self):26 self.assertEqual(push_button.get_score(7200, 0), 3)27 def test_append_log_last_pressed(self):28 push_button.LOG_FILE = "test_log.txt"29 push_button.LAST_PRESSED_FILE = "test_last.txt"30 push_button.append_log_last_pressed("username", 0, 1)31 with open(push_button.LOG_FILE, "r") as log_file:32 self.assertEqual(log_file.readlines(), ["username,0,1\n"])33 with open(push_button.LAST_PRESSED_FILE, "r") as last_file:34 self.assertEqual(last_file.readlines(), ["1"])35 os.remove(push_button.LOG_FILE)36 os.remove(push_button.LAST_PRESSED_FILE)37 def test_increment_score_new(self):38 push_button.SCORE_FILE = "test_score.txt"39 with open(push_button.SCORE_FILE, "w+") as write_file:40 write_file.write("")41 write_file.flush()42 push_button.increment_score("username", 1)43 with open(push_button.SCORE_FILE, "r") as score_file:44 self.assertEqual(score_file.readlines(), ["username,1\n"])45 os.remove(push_button.SCORE_FILE)46 def test_increment_score_existing(self):47 push_button.SCORE_FILE = "test_score.txt"48 with open(push_button.SCORE_FILE, "w+") as write_file:49 write_file.write("username,1")50 write_file.flush()51 push_button.increment_score("username", 1)52 with open(push_button.SCORE_FILE, "r") as score_file:53 self.assertEqual(score_file.readlines(), ["username,2\n"])54 os.remove(push_button.SCORE_FILE)55 def test_generate_recent(self):56 push_button.LOG_FILE = "test_log.txt"57 with open(push_button.LOG_FILE, "w+") as write_file:58 write_file.write("user1,0,1\n")59 write_file.flush()60 self.assertEqual(push_button.generate_recent(), "\U0001F7E9 (0) user1")61 os.remove(push_button.LOG_FILE)62 def test_generate_recent_many(self):63 push_button.LOG_FILE = "test_log.txt"64 with open(push_button.LOG_FILE, "w+") as write_file:65 write_file.write("user6,0,1\nuser5,0,1\nuser4,0,1\nuser3,0,1\nuser2,0,1\nuser1,0,1\n")66 write_file.flush()67 self.assertEqual(push_button.generate_recent(), "\U0001F7E9 (0) user1, \U0001F7E9 (0) user2, \U0001F7E9 (0) user3, \U0001F7E9 (0) user4, \U0001F7E9 (0) user5")68 os.remove(push_button.LOG_FILE)69 def test_generate_leaderboard(self):70 push_button.SCORE_FILE = "test_score.txt"71 with open(push_button.SCORE_FILE, "w+") as write_file:72 write_file.write("user1,0\n")73 write_file.flush()74 self.assertEqual(push_button.generate_leaderboard(), "1. \U0001F7E9 (0) user1\n")75 os.remove(push_button.SCORE_FILE)76 def test_generate_leaderboard_many(self):77 push_button.SCORE_FILE = "test_score.txt"78 with open(push_button.SCORE_FILE, "w+") as write_file:79 write_file.write("user1,1\nuser2,2\nuser3,3\nuser4,4\nuser5,5\nuser6,6\n")80 write_file.flush()81 self.assertEqual(push_button.generate_leaderboard(), "1. \U0001F7E9 (6) user6\n1. \U0001F7E9 (5) user5\n1. \U0001F7E9 (4) user4\n1. \U0001F7E9 (3) user3\n1. \U0001F7E9 (2) user2\n")82 os.remove(push_button.SCORE_FILE)83if __name__ == '__main__':...

Full Screen

Full Screen

test_file_util_file_regex.py

Source:test_file_util_file_regex.py Github

copy

Full Screen

...1011 def tearDown(self):12 print("\nCalling TestOSWrapper.tearDown()...")1314 def test_replace_in_file(self):15 # version = re.findall(regex, open(f).read())[0]16 file_path = "file_util_regex_replace_in_file.txt"17 find_text = r"__version__\s*=\s*['\"](.*?)['\"]"18 replace_with = "__version__ = '0.0.2.dev3'"19 # calling the replace method20 replace_in_file (file_path = file_path, regex_string = find_text,21 replace_with = replace_with)222324if __name__ == '__main__':25 ### 2 - invoke the framework ###26 # invoke the unittest framework27 # unittest.main() will capture all fo the tests28 # and run them 1-by-1. ...

Full Screen

Full Screen

test_tools.py

Source:test_tools.py Github

copy

Full Screen

...4from unittest import TestCase5from RTagsComplete.plugin import tools6class TestTools(TestCase):7 """Test Utilities."""8 def test_replace_in_file(self):9 """Test file string replace function."""10 name = ""11 with tempfile.NamedTemporaryFile(delete=False) as out_file:12 name = out_file.name13 contents = b'echo foo && sleep 1\n'14 out_file.write(contents)15 out_file.close()16 tools.Utilities.replace_in_file(17 "foo", "bar", name, {0: [6]})18 with open(name) as in_file:19 contents = in_file.read()20 self.assertEqual(contents, "echo bar && sleep 1\n")...

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 localstack 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