Best Python code snippet using slash
test_forth.py
Source:test_forth.py
1import unittest2import forth as solution3class TestCritic(unittest.TestCase):4 def test_indentation(self):5 code = ('def ugly(indent):\n'6 ' return indent')7 issues = solution.critic(code)8 self.assertSetEqual(set(issues[2]), {'indentation is 5 instead of 4'})9 def test_two_statements_on_one_line(self):10 code = 'a = 5; b = 6'11 issues = solution.critic(code)12 self.assertSetEqual(set(issues[1]),13 {'multiple expressions on the same line'})14 def test_too_deep_nesting(self):15 code = ("def some_func():\n"16 " for char in a_variable:\n"17 " if char != 'a':\n"18 " for _ in range(10):\n"19 " print('SOOOO MUUUCH INDENTATION')\n")20 issues = solution.critic(code, max_nesting=3)21 self.assertSetEqual(set(issues[5]), {'nesting too deep (4 > 3)'})22 def test_long_line_with_several_statements(self):23 code = ("def some_func():\n"24 " a_variable = 'some text';"25 " another_variable = 'some more text';"26 " even_moar_variables = 'just for to pass the time'")27 issues = solution.critic(code)28 self.assertSetEqual(set(issues[2]), {29 'line too long (116 > 79)',30 'multiple expressions on the same line'31 })32if __name__ == '__main__':33 unittest.main()34critic("""class TestCritic(unittest.TestCase):35 def test_indentation(self):36 code = ('def ugly(indent):\n'37 ' return indent')38 issues = solution.critic(code)39 self.assertSetEqual(set(issues[2]), {'indentation is 5 instead of 4'})40 def test_two_statements_on_one_line(self):41 code = 'a = 5; b = 6'42 issues = solution.critic(code)43 self.assertSetEqual(set(issues[1]),44 {'multiple expressions on the same line'})...
test_classdecorator.py
Source:test_classdecorator.py
...46 class awesome(object):47 inconsequential_stuff()48 awesome = should_work.with_dots(and_parens)(dotted.name(with_args(in_parens)(awesome)))"""49 self.check(b, a)50 def test_indentation(self):51 b = """52 if 1:53 if 2:54 if 3:55 @something56 @something_else57 class foo(bar):58 do_stuff()59 elif 4:60 pass"""61 a = """62 if 1:63 if 2:64 if 3:...
TestInlineTest.py
Source:TestInlineTest.py
2from lldbsuite.test.lldbtest import Base3import textwrap4class TestCommandParser(Base):5 mydir = Base.compute_mydir(__file__)6 def test_indentation(self):7 """Test indentation handling"""8 filename = self.getBuildArtifact("test_file.cpp")9 with open(filename, "w") as f:10 f.write(textwrap.dedent("""\11 int q;12 int w; //% first break13 int e;14 int r; //% second break15 //% continue second16 //% continuing indented17 //% not indented18 int t; //% third break19 """))20 p = CommandParser()...
5-text_indentation.py
Source:5-text_indentation.py
1#!/usr/bin/python32""" The test_indentation module """3def text_indentation(text):4 """splits a text into lines along "?", ":", "." """5 if type(text) is not str:6 raise TypeError("text must be a string")7 flag = 08 for a in text:9 if flag == 0:10 if a == ' ':11 continue12 else:13 flag = 114 if flag == 1:15 if a == '?' or a == '.' or a == ':':16 print(a)17 print()18 flag = 019 else:...
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!!