How to use parse_line method in autotest

Best Python code snippet using autotest_python

test_naive_cpp.py

Source:test_naive_cpp.py Github

copy

Full Screen

...15import unittest16class TestNaiveCpp(unittest.TestCase):17 def test_parse_line_arch(self):18 naive_cpp = NaiveCpp()19 naive_cpp.parse_line('/* a comment */')20 self.assertFalse(naive_cpp.in_aarch64_specific_code())21 naive_cpp.parse_line('#ifdef __aarch64__')22 self.assertTrue(naive_cpp.in_aarch64_specific_code())23 self.assertFalse(naive_cpp.in_other_arch_specific_code())24 naive_cpp.parse_line('asm("")')25 self.assertTrue(naive_cpp.in_aarch64_specific_code())26 self.assertFalse(naive_cpp.in_other_arch_specific_code())27 naive_cpp.parse_line('#else')28 self.assertFalse(naive_cpp.in_aarch64_specific_code())29 self.assertFalse(naive_cpp.in_other_arch_specific_code())30 naive_cpp.parse_line('asm("")')31 self.assertFalse(naive_cpp.in_aarch64_specific_code())32 self.assertFalse(naive_cpp.in_other_arch_specific_code())33 naive_cpp.parse_line('#endif')34 self.assertFalse(naive_cpp.in_aarch64_specific_code())35 naive_cpp.parse_line('#ifdef otherarch')36 self.assertFalse(naive_cpp.in_aarch64_specific_code())37 self.assertTrue(naive_cpp.in_other_arch_specific_code())38 naive_cpp.parse_line('asm("")')39 self.assertFalse(naive_cpp.in_aarch64_specific_code())40 self.assertTrue(naive_cpp.in_other_arch_specific_code())41 naive_cpp.parse_line('#else')42 self.assertFalse(naive_cpp.in_aarch64_specific_code())43 self.assertFalse(naive_cpp.in_other_arch_specific_code())44 naive_cpp.parse_line('asm("")')45 self.assertFalse(naive_cpp.in_aarch64_specific_code())46 self.assertFalse(naive_cpp.in_other_arch_specific_code())47 naive_cpp.parse_line('#endif')48 self.assertFalse(naive_cpp.in_aarch64_specific_code())49 self.assertFalse(naive_cpp.in_other_arch_specific_code())50 naive_cpp.parse_line('#if defined(__aarch64__)')51 self.assertTrue(naive_cpp.in_aarch64_specific_code())52 self.assertFalse(naive_cpp.in_other_arch_specific_code())53 naive_cpp.parse_line('asm("")')54 self.assertTrue(naive_cpp.in_aarch64_specific_code())55 self.assertFalse(naive_cpp.in_other_arch_specific_code())56 naive_cpp.parse_line('#else')57 self.assertFalse(naive_cpp.in_aarch64_specific_code())58 self.assertFalse(naive_cpp.in_other_arch_specific_code())59 naive_cpp.parse_line('asm("")')60 self.assertFalse(naive_cpp.in_aarch64_specific_code())61 self.assertFalse(naive_cpp.in_other_arch_specific_code())62 naive_cpp.parse_line('#endif')63 self.assertFalse(naive_cpp.in_aarch64_specific_code())64 self.assertFalse(naive_cpp.in_other_arch_specific_code())65 naive_cpp.parse_line('#if defined(otherarch)')66 self.assertFalse(naive_cpp.in_aarch64_specific_code())67 self.assertTrue(naive_cpp.in_other_arch_specific_code())68 naive_cpp.parse_line('asm("")')69 self.assertFalse(naive_cpp.in_aarch64_specific_code())70 self.assertTrue(naive_cpp.in_other_arch_specific_code())71 naive_cpp.parse_line('#else')72 self.assertFalse(naive_cpp.in_aarch64_specific_code())73 self.assertFalse(naive_cpp.in_other_arch_specific_code())74 naive_cpp.parse_line('asm("")')75 self.assertFalse(naive_cpp.in_aarch64_specific_code())76 self.assertFalse(naive_cpp.in_other_arch_specific_code())77 naive_cpp.parse_line('#endif')78 self.assertFalse(naive_cpp.in_aarch64_specific_code())79 self.assertFalse(naive_cpp.in_other_arch_specific_code())80 naive_cpp.parse_line('#ifdef __aarch64__')81 self.assertTrue(naive_cpp.in_aarch64_specific_code())82 self.assertFalse(naive_cpp.in_other_arch_specific_code())83 naive_cpp.parse_line('#ifdef foo')84 self.assertTrue(naive_cpp.in_aarch64_specific_code())85 self.assertFalse(naive_cpp.in_other_arch_specific_code())86 naive_cpp.parse_line('#endif')87 self.assertTrue(naive_cpp.in_aarch64_specific_code())88 self.assertFalse(naive_cpp.in_other_arch_specific_code())89 naive_cpp.parse_line('#endif')90 self.assertFalse(naive_cpp.in_aarch64_specific_code())91 self.assertFalse(naive_cpp.in_other_arch_specific_code())92 naive_cpp.parse_line('#ifdef foo')93 self.assertFalse(naive_cpp.in_aarch64_specific_code())94 self.assertFalse(naive_cpp.in_other_arch_specific_code())95 naive_cpp.parse_line('#ifdef __aarch64__')96 self.assertTrue(naive_cpp.in_aarch64_specific_code())97 self.assertFalse(naive_cpp.in_other_arch_specific_code())98 naive_cpp.parse_line('#endif')99 self.assertFalse(naive_cpp.in_aarch64_specific_code())100 self.assertFalse(naive_cpp.in_other_arch_specific_code())101 naive_cpp.parse_line('#endif')102 self.assertFalse(naive_cpp.in_aarch64_specific_code())103 self.assertFalse(naive_cpp.in_other_arch_specific_code())104 naive_cpp.parse_line('#if !defined(__aarch64__)')105 self.assertFalse(naive_cpp.in_aarch64_specific_code())106 self.assertFalse(naive_cpp.in_other_arch_specific_code())107 naive_cpp.parse_line('asm("")')108 self.assertFalse(naive_cpp.in_aarch64_specific_code())109 self.assertFalse(naive_cpp.in_other_arch_specific_code())110 naive_cpp.parse_line('#else')111 self.assertTrue(naive_cpp.in_aarch64_specific_code())112 self.assertFalse(naive_cpp.in_other_arch_specific_code())113 naive_cpp.parse_line('asm("")')114 self.assertTrue(naive_cpp.in_aarch64_specific_code())115 self.assertFalse(naive_cpp.in_other_arch_specific_code())116 naive_cpp.parse_line('#endif')117 self.assertFalse(naive_cpp.in_aarch64_specific_code())118 self.assertFalse(naive_cpp.in_other_arch_specific_code())119 naive_cpp.parse_line('#if !defined(otherarch)')120 self.assertFalse(naive_cpp.in_aarch64_specific_code())121 self.assertFalse(naive_cpp.in_other_arch_specific_code())122 naive_cpp.parse_line('asm("")')123 self.assertFalse(naive_cpp.in_aarch64_specific_code())124 self.assertFalse(naive_cpp.in_other_arch_specific_code())125 naive_cpp.parse_line('#else')126 self.assertFalse(naive_cpp.in_aarch64_specific_code())127 self.assertTrue(naive_cpp.in_other_arch_specific_code())128 naive_cpp.parse_line('asm("")')129 self.assertFalse(naive_cpp.in_aarch64_specific_code())130 self.assertTrue(naive_cpp.in_other_arch_specific_code())131 naive_cpp.parse_line('#endif')132 naive_cpp.parse_line('#if __aarch64__')133 self.assertTrue(naive_cpp.in_aarch64_specific_code())134 self.assertFalse(naive_cpp.in_other_arch_specific_code())135 naive_cpp.parse_line('asm("")')136 self.assertTrue(naive_cpp.in_aarch64_specific_code())137 self.assertFalse(naive_cpp.in_other_arch_specific_code())138 naive_cpp.parse_line('#else')139 self.assertFalse(naive_cpp.in_aarch64_specific_code())140 self.assertFalse(naive_cpp.in_other_arch_specific_code())141 naive_cpp.parse_line('asm("")')142 self.assertFalse(naive_cpp.in_aarch64_specific_code())143 self.assertFalse(naive_cpp.in_other_arch_specific_code())144 naive_cpp.parse_line('#endif')145 self.assertFalse(naive_cpp.in_aarch64_specific_code())146 self.assertFalse(naive_cpp.in_other_arch_specific_code())147 naive_cpp.parse_line('#if otherarch')148 self.assertFalse(naive_cpp.in_aarch64_specific_code())149 self.assertTrue(naive_cpp.in_other_arch_specific_code())150 naive_cpp.parse_line('asm("")')151 self.assertFalse(naive_cpp.in_aarch64_specific_code())152 self.assertTrue(naive_cpp.in_other_arch_specific_code())153 naive_cpp.parse_line('#else')154 self.assertFalse(naive_cpp.in_aarch64_specific_code())155 self.assertFalse(naive_cpp.in_other_arch_specific_code())156 naive_cpp.parse_line('asm("")')157 self.assertFalse(naive_cpp.in_aarch64_specific_code())158 self.assertFalse(naive_cpp.in_other_arch_specific_code())159 naive_cpp.parse_line('#endif')160 self.assertFalse(naive_cpp.in_aarch64_specific_code())161 self.assertFalse(naive_cpp.in_other_arch_specific_code())162 naive_cpp.parse_line('#if !__aarch64__')163 self.assertFalse(naive_cpp.in_aarch64_specific_code())164 self.assertFalse(naive_cpp.in_other_arch_specific_code())165 naive_cpp.parse_line('asm("")')166 self.assertFalse(naive_cpp.in_aarch64_specific_code())167 self.assertFalse(naive_cpp.in_other_arch_specific_code())168 naive_cpp.parse_line('#else')169 self.assertTrue(naive_cpp.in_aarch64_specific_code())170 self.assertFalse(naive_cpp.in_other_arch_specific_code())171 naive_cpp.parse_line('asm("")')172 self.assertTrue(naive_cpp.in_aarch64_specific_code())173 self.assertFalse(naive_cpp.in_other_arch_specific_code())174 naive_cpp.parse_line('#endif')175 self.assertFalse(naive_cpp.in_aarch64_specific_code())176 self.assertFalse(naive_cpp.in_other_arch_specific_code())177 naive_cpp.parse_line('#if !otherarch')178 self.assertFalse(naive_cpp.in_aarch64_specific_code())179 self.assertFalse(naive_cpp.in_other_arch_specific_code())180 naive_cpp.parse_line('asm("")')181 self.assertFalse(naive_cpp.in_aarch64_specific_code())182 self.assertFalse(naive_cpp.in_other_arch_specific_code())183 naive_cpp.parse_line('#else')184 self.assertFalse(naive_cpp.in_aarch64_specific_code())185 self.assertTrue(naive_cpp.in_other_arch_specific_code())186 naive_cpp.parse_line('asm("")')187 self.assertFalse(naive_cpp.in_aarch64_specific_code())188 self.assertTrue(naive_cpp.in_other_arch_specific_code())189 naive_cpp.parse_line('#endif')190 self.assertFalse(naive_cpp.in_aarch64_specific_code())191 self.assertFalse(naive_cpp.in_other_arch_specific_code())192 naive_cpp.parse_line('#if defined ( __aarch64__)')193 self.assertTrue(naive_cpp.in_aarch64_specific_code())194 self.assertFalse(naive_cpp.in_other_arch_specific_code())195 naive_cpp.parse_line('asm("")')196 self.assertTrue(naive_cpp.in_aarch64_specific_code())197 self.assertFalse(naive_cpp.in_other_arch_specific_code())198 naive_cpp.parse_line('#endif')199 self.assertFalse(naive_cpp.in_aarch64_specific_code())200 self.assertFalse(naive_cpp.in_other_arch_specific_code())201 naive_cpp.parse_line('#if ! defined ( __aarch64__)')202 self.assertFalse(naive_cpp.in_aarch64_specific_code())203 self.assertFalse(naive_cpp.in_other_arch_specific_code())204 naive_cpp.parse_line('asm("")')205 self.assertFalse(naive_cpp.in_aarch64_specific_code())206 self.assertFalse(naive_cpp.in_other_arch_specific_code())207 naive_cpp.parse_line('#else')208 self.assertTrue(naive_cpp.in_aarch64_specific_code())209 self.assertFalse(naive_cpp.in_other_arch_specific_code())210 naive_cpp.parse_line('asm("")')211 self.assertTrue(naive_cpp.in_aarch64_specific_code())212 self.assertFalse(naive_cpp.in_other_arch_specific_code())213 naive_cpp.parse_line('#endif')214 self.assertFalse(naive_cpp.in_aarch64_specific_code())215 self.assertFalse(naive_cpp.in_other_arch_specific_code())216 naive_cpp.parse_line('#if aarch64')217 self.assertTrue(naive_cpp.in_aarch64_specific_code())218 self.assertFalse(naive_cpp.in_other_arch_specific_code())219 naive_cpp.parse_line('asm("")')220 self.assertTrue(naive_cpp.in_aarch64_specific_code())221 self.assertFalse(naive_cpp.in_other_arch_specific_code())222 naive_cpp.parse_line('#elif otherarch')223 self.assertFalse(naive_cpp.in_aarch64_specific_code())224 self.assertTrue(naive_cpp.in_other_arch_specific_code())225 naive_cpp.parse_line('asm("")')226 self.assertFalse(naive_cpp.in_aarch64_specific_code())227 self.assertTrue(naive_cpp.in_other_arch_specific_code())228 naive_cpp.parse_line('#endif')229 self.assertFalse(naive_cpp.in_aarch64_specific_code())230 self.assertFalse(naive_cpp.in_other_arch_specific_code())231 def test_parse_line_pragma(self):232 naive_cpp = NaiveCpp()233 result = naive_cpp.parse_line('#pragma simd foo')234 self.assertEqual(result.directive_type,235 PreprocessorDirective.TYPE_PRAGMA)236 def test_parse_line_error(self):237 naive_cpp = NaiveCpp()238 result = naive_cpp.parse_line('#error foo')239 self.assertEqual(result.directive_type,240 PreprocessorDirective.TYPE_ERROR)241 def test_parse_line_ifdef_compiler(self):242 naive_cpp = NaiveCpp()243 result = naive_cpp.parse_line('#ifdef __GNUC__')244 self.assertEqual(result.directive_type,245 PreprocessorDirective.TYPE_CONDITIONAL)246 self.assertTrue(result.is_compiler)247 def test_aarch64_re(self):248 match = NaiveCpp.AARCH64_MACROS_RE_PROG.match('aarch64')249 self.assertIsNotNone(match)250 match = NaiveCpp.AARCH64_MACROS_RE_PROG.match('__aarch64__')251 self.assertIsNotNone(match)252 match = NaiveCpp.AARCH64_MACROS_RE_PROG.match('foo')253 self.assertIsNone(match)254 def test_non_aarch64_re(self):255 match = NaiveCpp.NON_AARCH64_MACROS_RE_PROG.match('otherarch')256 self.assertIsNotNone(match)257 match = NaiveCpp.NON_AARCH64_MACROS_RE_PROG.match('__otherarch__')258 self.assertIsNotNone(match)259 match = NaiveCpp.NON_AARCH64_MACROS_RE_PROG.match('foo')260 self.assertIsNone(match)261 def test_compiler_re(self):262 match = NaiveCpp.COMPILER_MACROS_RE_PROG.match('GNUC')263 self.assertIsNotNone(match)264 match = NaiveCpp.COMPILER_MACROS_RE_PROG.match('__GNUC__')265 self.assertIsNotNone(match)266 match = NaiveCpp.COMPILER_MACROS_RE_PROG.match('foo')267 self.assertIsNone(match)268 def test_macro_body(self):269 naive_cpp = NaiveCpp()270 result = naive_cpp.parse_line('#define MACRO BODY')271 self.assertEqual(result.directive_type,272 PreprocessorDirective.TYPE_DEFINE)273 self.assertEqual(result.macro_name, 'MACRO')274 self.assertEqual(result.body, 'BODY')275 result = naive_cpp.parse_line('#define MACRO(a,b,c) BODY')276 self.assertEqual(result.directive_type,277 PreprocessorDirective.TYPE_DEFINE)278 self.assertEqual(result.macro_name, 'MACRO(a,b,c)')279 self.assertEqual(result.body, 'BODY')280 def test_parse_line_if_else(self):281 naive_cpp = NaiveCpp()282 naive_cpp.parse_line('/* a comment */')283 self.assertFalse(naive_cpp.in_aarch64_specific_code())284 self.assertFalse(naive_cpp.in_other_arch_specific_code())285 self.assertFalse(naive_cpp.in_other_arch_else_code())286 naive_cpp.parse_line('#if defined (__otherarch__)')287 self.assertFalse(naive_cpp.in_aarch64_specific_code())288 self.assertTrue(naive_cpp.in_other_arch_specific_code())289 self.assertFalse(naive_cpp.in_other_arch_else_code())290 naive_cpp.parse_line('/* a comment */')291 self.assertFalse(naive_cpp.in_aarch64_specific_code())292 self.assertTrue(naive_cpp.in_other_arch_specific_code())293 self.assertFalse(naive_cpp.in_other_arch_else_code())294 naive_cpp.parse_line('#else')295 self.assertFalse(naive_cpp.in_aarch64_specific_code())296 self.assertFalse(naive_cpp.in_other_arch_specific_code())297 self.assertTrue(naive_cpp.in_other_arch_else_code())298 naive_cpp.parse_line('/* a comment */')299 self.assertFalse(naive_cpp.in_aarch64_specific_code())300 self.assertFalse(naive_cpp.in_other_arch_specific_code())301 self.assertTrue(naive_cpp.in_other_arch_else_code())302 naive_cpp.parse_line('#endif')303 self.assertFalse(naive_cpp.in_aarch64_specific_code())304 self.assertFalse(naive_cpp.in_other_arch_specific_code())305 self.assertFalse(naive_cpp.in_other_arch_else_code())306 def test_parse_line_if_elif_else(self):307 naive_cpp = NaiveCpp()308 naive_cpp.parse_line('/* a comment */')309 self.assertFalse(naive_cpp.in_aarch64_specific_code())310 self.assertFalse(naive_cpp.in_other_arch_specific_code())311 self.assertFalse(naive_cpp.in_other_arch_else_code())312 naive_cpp.parse_line('#if defined (__otherarch__)')313 self.assertFalse(naive_cpp.in_aarch64_specific_code())314 self.assertTrue(naive_cpp.in_other_arch_specific_code())315 self.assertFalse(naive_cpp.in_other_arch_else_code())316 naive_cpp.parse_line('/* a comment */')317 self.assertFalse(naive_cpp.in_aarch64_specific_code())318 self.assertTrue(naive_cpp.in_other_arch_specific_code())319 self.assertFalse(naive_cpp.in_other_arch_else_code())320 naive_cpp.parse_line('#elif defined (__aarch64__)')321 self.assertTrue(naive_cpp.in_aarch64_specific_code())322 self.assertFalse(naive_cpp.in_other_arch_specific_code())323 self.assertFalse(naive_cpp.in_other_arch_else_code())324 naive_cpp.parse_line('/* a comment */')325 self.assertTrue(naive_cpp.in_aarch64_specific_code())326 self.assertFalse(naive_cpp.in_other_arch_specific_code())327 self.assertFalse(naive_cpp.in_other_arch_else_code())328 naive_cpp.parse_line('#else')329 self.assertFalse(naive_cpp.in_aarch64_specific_code())330 self.assertFalse(naive_cpp.in_other_arch_specific_code())331 self.assertFalse(naive_cpp.in_other_arch_else_code())332 naive_cpp.parse_line('/* a comment */')333 self.assertFalse(naive_cpp.in_aarch64_specific_code())334 self.assertFalse(naive_cpp.in_other_arch_specific_code())335 self.assertFalse(naive_cpp.in_other_arch_else_code())336 naive_cpp.parse_line('#endif')337 self.assertFalse(naive_cpp.in_aarch64_specific_code())338 self.assertFalse(naive_cpp.in_other_arch_specific_code())339 self.assertFalse(naive_cpp.in_other_arch_else_code())340 def test_parse_line_if_elif_elif_else(self):341 naive_cpp = NaiveCpp()342 naive_cpp.parse_line('/* a comment */')343 self.assertFalse(naive_cpp.in_aarch64_specific_code())344 self.assertFalse(naive_cpp.in_other_arch_specific_code())345 self.assertFalse(naive_cpp.in_other_arch_else_code())346 naive_cpp.parse_line('#if defined (__otherarch__)')347 self.assertFalse(naive_cpp.in_aarch64_specific_code())348 self.assertTrue(naive_cpp.in_other_arch_specific_code())349 self.assertFalse(naive_cpp.in_other_arch_else_code())350 naive_cpp.parse_line('/* a comment */')351 self.assertFalse(naive_cpp.in_aarch64_specific_code())352 self.assertTrue(naive_cpp.in_other_arch_specific_code())353 self.assertFalse(naive_cpp.in_other_arch_else_code())354 naive_cpp.parse_line('#elif defined (__aarch64__)')355 self.assertTrue(naive_cpp.in_aarch64_specific_code())356 self.assertFalse(naive_cpp.in_other_arch_specific_code())357 self.assertFalse(naive_cpp.in_other_arch_else_code())358 naive_cpp.parse_line('/* a comment */')359 self.assertTrue(naive_cpp.in_aarch64_specific_code())360 self.assertFalse(naive_cpp.in_other_arch_specific_code())361 self.assertFalse(naive_cpp.in_other_arch_else_code())362 naive_cpp.parse_line('#elif defined (__otherarch__)')363 self.assertFalse(naive_cpp.in_aarch64_specific_code())364 self.assertTrue(naive_cpp.in_other_arch_specific_code())365 self.assertFalse(naive_cpp.in_other_arch_else_code())366 naive_cpp.parse_line('/* a comment */')367 self.assertFalse(naive_cpp.in_aarch64_specific_code())368 self.assertTrue(naive_cpp.in_other_arch_specific_code())369 self.assertFalse(naive_cpp.in_other_arch_else_code())370 naive_cpp.parse_line('#else')371 self.assertFalse(naive_cpp.in_aarch64_specific_code())372 self.assertFalse(naive_cpp.in_other_arch_specific_code())373 self.assertFalse(naive_cpp.in_other_arch_else_code())374 naive_cpp.parse_line('/* a comment */')375 self.assertFalse(naive_cpp.in_aarch64_specific_code())376 self.assertFalse(naive_cpp.in_other_arch_specific_code())377 self.assertFalse(naive_cpp.in_other_arch_else_code())378 naive_cpp.parse_line('#endif')379 self.assertFalse(naive_cpp.in_aarch64_specific_code())380 self.assertFalse(naive_cpp.in_other_arch_specific_code())...

Full Screen

Full Screen

test_parser.py

Source:test_parser.py Github

copy

Full Screen

...100 - '%{datetime} %{level} %{msg}'101 """102 cfg = yaml.load(StringIO(cfg))103 psr = ps.create_parser(cfg['parser'])104 assert psr.parse_line('2016-06-28 12:33:21 DEBUG foo.py:37 Init success')105 assert psr.parsed['date'] == '2016-06-28'106 assert psr.parsed['level'] == 'DEBUG'107 assert psr.parsed['src_line'] == '37'108 assert psr.parse_line('2016-06-29 17:50:11 ERROR Critical error!')109 assert psr.parsed['level'] == 'ERROR'110 assert psr.parsed['msg'] == 'Critical error!'111 assert not psr.parse_line('2016-06-29 ERROR')112def test_parser_create_custom():113 cfg = """114parser:115 custom: FCS116 """117 import yaml118 from StringIO import StringIO119 cfg = yaml.load(StringIO(cfg))120 psr = ps.create_parser(cfg['parser'])121 assert isinstance(psr, custom.FCS)122def test_parser_fcs():123 fcs = custom.FCS()124 fcs.set_file_path("dummy_path\FCSAdapter.dll.log.20160420-092124.19316")125 # assert fcs.get_date() == '2016-04-20'126 assert fcs.parse_line("E20160324 09:26:51.754881 2708 fcs_client.cpp:225] connection closed : 997")127 assert fcs.buf['dt_'] == '2016-03-24 09:26:51.754881'128 assert fcs.buf['level'] == 'E'129 assert fcs.buf['msg'] == 'connection closed : 997'130 assert len(fcs.buf) == 9131 assert fcs.completed == 0132 assert fcs.parse_line("E20160325 11:37:52.508764 3304 communicator.hpp:128] [8371] response sync")133 assert len(fcs.parsed) == 9134 assert fcs.buf['dt_'] == '2016-03-25 11:37:52.508764'135 assert fcs.completed == 1136 assert fcs.parse_line(" [RequestValidateAuthenticationKey]")137 assert fcs.buf['type'] == 'ValidateAuthenticationKey'138 fcs.parse_line(" packet_length : 67")139 assert fcs.buf["req-packet_length"] == '67'140 fcs.parse_line(" packet_type : 0x26")141 fcs.parse_line(" transaction_id : 8371")142 fcs.parse_line(" account_no : 1862710")143 fcs.parse_line(" authentication_key : D7665F56-29E2-4B80-BD8F-C5D37C3654CA")144 assert fcs.buf["req-authentication_key"] == "D7665F56-29E2-4B80-BD8F-C5D37C3654CA"145 fcs.parse_line(" client_ip : 116.121.77.141")146 assert fcs.buf["req-client_ip"] == '116.121.77.141'147 fcs.parse_line(" [ResponseValidateAuthenticationKey]")148 fcs.parse_line(" packet_length : 44")149 assert fcs.buf["res-packet_length"] == '44'150 fcs.parse_line(" packet_type : 0x26")151 fcs.parse_line(" transaction_id : 8371")152 fcs.parse_line(" result_code : 90213")153 fcs.parse_line(" condition_type : 0x64")154 fcs.parse_line(" user_no : 0")155 fcs.parse_line(" user_id : ")156 fcs.parse_line(" account_no : 0")157 fcs.parse_line(" account_id : ")158 fcs.parse_line(" account_type : 0x00")159 fcs.parse_line(" block_state : 0x00")160 fcs.parse_line(" pcbang_index : 0")161 fcs.parse_line(" phone_auth : ")162 fcs.parse_line(" is_phone_auth : 0")163 fcs.parse_line(" auth_ip : ")164 assert fcs.buf["res-auth_ip"] == ''165 fcs.parse_line("E20160324 11:39:31.027815 3316 communicator.hpp:128] [8481] response sync")166 assert len(fcs.parsed) == 31167 assert fcs.parsed["res-auth_ip"] == ''168 assert len(fcs.buf) == 9169 assert fcs.completed == 2170 assert fcs.parse_line("I20160420 11:48:24.739433 26224 communicator.hpp:124] [3362162] response sync")171 fcs.parse_line(" [ResponseGetPCRoomGuid]")172 fcs.parse_line(" packet_length : 14")173 fcs.parse_line(" packet_type : 0x34")174 fcs.parse_line(" transaction_id : 3362162")175 fcs.parse_line(" result_code : 1")176 fcs.parse_line(" condition_type : 0x64")177 fcs.parse_line(" pc_room_guid : 0")178 assert fcs.buf['level'] == 'I'179 assert fcs.buf['dt_'] == '2016-04-20 11:48:24.739433'180 fcs.parse_line("I20160420 11:48:24.739433 26224 communicator.hpp:133] [3362162] <total: 0 msec>")181 assert fcs.buf['transaction_id'] == '3362162'182 assert fcs.buf['dt_'] == '2016-04-20 11:48:24.739433'183 assert fcs.buf['totalms'] == '0'184 fcs.parse_line("I20170104 14:31:26.525174 10828 communicator.hpp:165] [4] request async")185 assert '[4] request async' in fcs.buf['msg']186 fcs.parse_line(" [RequestChargeJewel]")187 fcs.parse_line(" packet_length : 171")188 assert 'req-packet_length' in fcs.buf189 fcs.parse_line(" packet_type : 0xb0")190 fcs.parse_line(" transaction_id : 4")191 fcs.parse_line(" callback_attribute :callback attr")192 fcs.parse_line(" provider_code :PRC001")193 fcs.parse_line(" user_no :10000149")194 assert 'req-user_no' in fcs.buf195 fcs.parse_line("I20170327 22:31:42.046875 1440 fcs_client.h:114] [963080] response async")196 assert '[963080] response async' in fcs.buf['msg']197 fcs.parse_line(" [ResponseWShopCheckBalance]")198 fcs.parse_line(" packet_length : 75")199 assert 'res-packet_length' in fcs.buf200 fcs.parse_line(" jewel_balance_item_count : 1")201 # can not parse indented key values202 fcs.parse_line(" JewelBalanceItem[0]")203 fcs.parse_line(" cash_type : 3")204 fcs.parse_line(" value : 500")205 fcs.parse_line("I20170327 22:31:43.281250 1440 fcs_client.h:114] [963104] response async")206 assert '[963104] response async' in fcs.buf['msg']207 fcs.parse_line(" [ResponseWShopCheckBalance]")208 fcs.parse_line(" packet_length : 75")209 fcs.parse_line(" callback_attribute : J6402170601804509986")210 fcs.parse_line(" jewel_balance_item_count : 1")211 assert "res-jewel_balance_item_count" in fcs.buf212def test_parser_mocaa():213 moc = custom.Mocaa()214 # dtregx = moc.objects['%{datetime}']215 # assert dtregx.regex == r'(?P<datetime>\d{4}/\d{2}/\d{2} \d{2}:\d{2}:\d{2} \(\+\d{2}\d{2}\))'216 assert moc.parse_line("==== 2016/06/01 02:51:19 (+0900) ====")217 assert moc.parse_line("[API Request][c6b3d85e-1f60-47e8-a07c-4379db9c2bc6] /v2/contents/start")218 assert moc.buf['ltype'] == 'API Request'219 assert moc.parse_line('{"service_code":"SVC009","store_type":"playstore","params":"","client_ip":"192.168.0.11"}')220 assert moc.parse_line('==== 2016-06-01 02:51:19 (+0900) ====')221 assert moc.completed == 1222 assert moc.parsed['ltype'] == 'API Request'223 assert moc.parse_line('[API Response][c6b3d85e-1f60-47e8-a07c-4379db9c2bc6][898 ms] /v2/contents/start')224 assert moc.parse_line('[Body]')225 assert moc.parse_line('{')226 assert moc.parse_line(' "return_code": 1,')227 assert moc.parse_line(' "url": {')228 assert moc.parse_line(' "notice_url": "",')229 assert moc.parse_line(' "event_url": "",')230 assert moc.parse_line(' "cs_url": "",')231 assert moc.parse_line(' "faq_url": "",')232 assert moc.parse_line(' "coupon_url": ""')233 assert moc.parse_line(' },')234 assert moc.parse_line(' "maintenance": {')235 assert moc.parse_line(' "is_open": true,')236 assert moc.parse_line(' "message": ""')237 assert moc.parse_line(' },')238 assert moc.parse_line(' "webzen_kr_auth": null,')239 assert moc.parse_line(' "webzen_global_auth": null,')240 assert moc.parse_line(' "naver_auth": null,')241 assert moc.parse_line(' "google_plus_auth": null,')242 assert moc.parse_line(' "t_store": null,')243 assert moc.parse_line(' "n_store": null,')244 assert moc.parse_line(' "push_notification": {')245 assert moc.parse_line(' "gcm": "392205420186"')246 assert moc.parse_line(' },')247 assert moc.parse_line(' "google_play_game_service": {')248 assert moc.parse_line(' "client_id": "",')249 assert moc.parse_line(' "client_secret": ""')250 assert moc.parse_line(' },')251 assert moc.parse_line(' "google_auth": null,')252 assert moc.parse_line(' "memo": "success"')253 assert moc.parse_line('}')254 assert moc.buf['memo'] == 'success'255 assert moc.parse_line("==== 2016/06/01 02:51:20 (+0900) ====")256 assert moc.completed == 2257def test_parser_transform():258 cfg = """259parser:260 tokens:261 date: '\d{4}-\d{2}-\d{2}'262 time: '\d{2}:\d{2}:\d{2}.\d{4}'263 dt_: '%{date} %{time}'264 request_data: ['{.*}', 'prefix(lower(ravel(json(_))), "req")']265 message: ['{.*}', 'ravel(json(_))']266 exception: '.*'267 groups:268 debug: '%{dt_},%{request_data}?,%{message}?'269 formats:270 - '%{debug}'271 """272 cfg = yaml.load(StringIO(cfg))273 psr = ps.create_parser(cfg['parser'])274 tok = psr.objects['%{request_data}']275 ok = tok.parse('{"PostData" : {"val": 1, "lval": [1,2,3]},"GetData" : {}}')276 assert ok277 assert 'request_data' not in tok.taken278 assert "req-postdata_val" in tok.taken279 assert "req-postdata_lval" in tok.taken280 assert "req-getdata" not in tok.taken281 assert psr.objects['%{request_data}'].tfunc_lmap282 ok = psr.parse_line('2016-07-25 00:00:00.7083,{"PostData" : {"val": 1, "lval": [1,2,3]},"GetData" : {}},')283 assert "req-postdata_val" in psr.parsed284 assert "req-postdata_lval" in psr.parsed285 assert "req-getdata" not in psr.parsed286 assert psr.parsed['message'] == ''287# def test_parser_multiline():288# cfg = """289# parser:290# tokens:291# date: '\d{4}-\d{2}-\d{2}'292# time: '\d{2}:\d{2}:\d{2}.\d{4}'293# dt_: '%{date} %{time}'294# path: '\S+'295# state: '\d+'296# server_ip: '\d+\.\d+\.\d+\.\d+'...

Full Screen

Full Screen

test_gmachine.py

Source:test_gmachine.py Github

copy

Full Screen

...13 pass14 def test_reset(self):15 # reset() resets all configurable from gcode things.16 m = GMachine()17 m.do_command(GCode.parse_line("G20"))18 m.do_command(GCode.parse_line("G91"))19 m.do_command(GCode.parse_line("X1Y1Z1"))20 m.reset()21 m.do_command(GCode.parse_line("X3Y4Z5E6"))22 self.assertEqual(m.position(), Coordinates(3, 4, 5, 6))23 def test_safe_zero(self):24 m = GMachine()25 m.do_command(GCode.parse_line("X1Y2Z3E4"))26 m.safe_zero()27 self.assertEqual(m.position(), Coordinates(0, 0, 0, 4))28 def test_none(self):29 # GMachine must ignore None commands, since GCode.parse_line()30 # returns None if no gcode found in line.31 m = GMachine()32 m.do_command(None)33 self.assertEqual(m.position(), Coordinates(0, 0, 0, 0))34 def test_unknown(self):35 # Test commands which doesn't exists36 m = GMachine()37 self.assertRaises(GMachineException,38 m.do_command, GCode.parse_line("G99699X1Y2Z3"))39 self.assertRaises(GMachineException,40 m.do_command, GCode.parse_line("M99699"))41 # Test gcode commands.42 def test_g0_g1(self):43 m = GMachine()44 m.do_command(GCode.parse_line("G0X10Y10Z11"))45 self.assertEqual(m.position(), Coordinates(10, 10, 11, 0))46 m.do_command(GCode.parse_line("G0X3Y2Z1E-2"))47 self.assertEqual(m.position(), Coordinates(3, 2, 1, -2))48 m.do_command(GCode.parse_line("G1X1Y2Z3E4"))49 self.assertEqual(m.position(), Coordinates(1, 2, 3, 4))50 self.assertRaises(GMachineException,51 m.do_command, GCode.parse_line("G1F-1"))52 self.assertRaises(GMachineException,53 m.do_command, GCode.parse_line("G1X-1Y0Z0"))54 self.assertRaises(GMachineException,55 m.do_command, GCode.parse_line("G1X0Y-1Z0"))56 self.assertRaises(GMachineException,57 m.do_command, GCode.parse_line("G1X0Y0Z-1"))58 def test_feed_rate(self):59 PulseGenerator.AUTO_VELOCITY_ADJUSTMENT = False60 m = GMachine()61 self.assertRaises(GMachineException,62 m.do_command, GCode.parse_line("G1X1F-1"))63 cl = "G1X1F" + str(MIN_VELOCITY_MM_PER_MIN - 0.0000001)64 self.assertRaises(GMachineException, m.do_command,65 GCode.parse_line(cl))66 m.do_command(GCode.parse_line("G1X100F"67 + str(MAX_VELOCITY_MM_PER_MIN_X)))68 m.do_command(GCode.parse_line("G1Y100F"69 + str(MAX_VELOCITY_MM_PER_MIN_Y)))70 m.do_command(GCode.parse_line("G1Z100F"71 + str(MAX_VELOCITY_MM_PER_MIN_Z)))72 m.do_command(GCode.parse_line("G1E100F"73 + str(MAX_VELOCITY_MM_PER_MIN_E)))74 self.assertRaises(GMachineException,75 m.do_command, GCode.parse_line("G1X0F999999"))76 s = "G1X0F" + str(MAX_VELOCITY_MM_PER_MIN_X + 1)77 self.assertRaises(GMachineException, m.do_command, GCode.parse_line(s))78 s = "G1Y0F" + str(MAX_VELOCITY_MM_PER_MIN_Y + 1)79 self.assertRaises(GMachineException, m.do_command, GCode.parse_line(s))80 s = "G1Z0F" + str(MAX_VELOCITY_MM_PER_MIN_Z + 1)81 self.assertRaises(GMachineException, m.do_command, GCode.parse_line(s))82 s = "G1E0F" + str(MAX_VELOCITY_MM_PER_MIN_E + 1)83 self.assertRaises(GMachineException, m.do_command, GCode.parse_line(s))84 PulseGenerator.AUTO_VELOCITY_ADJUSTMENT = True85 m.do_command(GCode.parse_line("G1X10Y10Z10F9999999999999999999"))86 m.do_command(GCode.parse_line("G2I0.1F9999999999999999999"))87 m.do_command(GCode.parse_line("G2I10F9999999999999999999"))88 PulseGenerator.AUTO_VELOCITY_ADJUSTMENT = AUTO_VELOCITY_ADJUSTMENT89 def test_g2_g3(self):90 m = GMachine()91 self.assertRaises(GMachineException,92 m.do_command, GCode.parse_line("G3I1J1F-1"))93 m.do_command(GCode.parse_line("G19"))94 self.assertRaises(GMachineException,95 m.do_command, GCode.parse_line("G3I1J0K0"))96 m.do_command(GCode.parse_line("G18"))97 self.assertRaises(GMachineException,98 m.do_command, GCode.parse_line("G3I0J1K0"))99 m.do_command(GCode.parse_line("G17"))100 self.assertRaises(GMachineException,101 m.do_command, GCode.parse_line("G3I0J0K1"))102 self.assertRaises(GMachineException,103 m.do_command, GCode.parse_line("G2X99999999Y99999999"104 "I1J1"))105 self.assertRaises(GMachineException,106 m.do_command,107 GCode.parse_line("G2X2Y2Z99999999I1J1"))108 self.assertEqual(m.position(), Coordinates(0, 0, 0, 0))109 self.assertRaises(GMachineException,110 m.do_command, GCode.parse_line("G2X4Y4I2J2"))111 self.assertRaises(GMachineException,112 m.do_command, GCode.parse_line("G3X4Y4I2J2"))113 m.do_command(GCode.parse_line("G17"))114 m.do_command(GCode.parse_line("G1X1"))115 m.do_command(GCode.parse_line("G2J1"))116 m.do_command(GCode.parse_line("G3J1"))117 self.assertEqual(m.position(), Coordinates(1, 0, 0, 0))118 m.do_command(GCode.parse_line("G1X10Y10"))119 m.do_command(GCode.parse_line("G2X9I1"))120 self.assertEqual(m.position(), Coordinates(9, 10, 0, 0))121 m.do_command(GCode.parse_line("G19"))122 m.do_command(GCode.parse_line("G1X10Y10Z10"))123 m.do_command(GCode.parse_line("G3Y8K1"))124 self.assertEqual(m.position(), Coordinates(10, 8, 10, 0))125 m.do_command(GCode.parse_line("G17"))126 m.do_command(GCode.parse_line("G1X5Y5Z0"))127 m.do_command(GCode.parse_line("G2X0Y0Z5I-2J-2"))128 self.assertEqual(m.position(), Coordinates(0, 0, 5, 0))129 m.do_command(GCode.parse_line("G17"))130 m.do_command(GCode.parse_line("G1X90Y90"))131 m.do_command(GCode.parse_line("G2X90Y70I-5J-5"))132 self.assertEqual(m.position(), Coordinates(90, 70, 5, 0))133 m.do_command(GCode.parse_line("G18"))134 m.do_command(GCode.parse_line("G1X90Y90Z20E0"))135 m.do_command(GCode.parse_line("G2Z20X70I-5K-5E22"))136 self.assertEqual(m.position(), Coordinates(70, 90, 20, 22))137 m.do_command(GCode.parse_line("G19"))138 m.do_command(GCode.parse_line("G1X90Y90Z20"))139 m.do_command(GCode.parse_line("G2Y90Z0J-5K-5E27"))140 self.assertEqual(m.position(), Coordinates(90, 90, 0, 27))141 def test_g4(self):142 m = GMachine()143 st = time.time()144 m.do_command(GCode.parse_line("G4P0.5"))145 self.assertLess(0.5, time.time() - st)146 self.assertRaises(GMachineException,147 m.do_command, GCode.parse_line("G4P-0.5"))148 def test_g17_g18_g19(self):149 m = GMachine()150 m.do_command(GCode.parse_line("G19"))151 self.assertEqual(m.plane(), PLANE_YZ)152 m.do_command(GCode.parse_line("G18"))153 self.assertEqual(m.plane(), PLANE_ZX)154 m.do_command(GCode.parse_line("G17"))155 self.assertEqual(m.plane(), PLANE_XY)156 def test_g20_g21(self):157 m = GMachine()158 m.do_command(GCode.parse_line("G20"))159 m.do_command(GCode.parse_line("X3Y2Z1E0.5"))160 self.assertEqual(m.position(), Coordinates(76.2, 50.8, 25.4, 12.7))161 m.do_command(GCode.parse_line("G21"))162 m.do_command(GCode.parse_line("X3Y2Z1E0.5"))163 self.assertEqual(m.position(), Coordinates(3, 2, 1, 0.5))164 def test_g90_g91(self):165 m = GMachine()166 m.do_command(GCode.parse_line("G91"))167 m.do_command(GCode.parse_line("X1Y1Z1E1"))168 m.do_command(GCode.parse_line("X1Y1Z1"))169 m.do_command(GCode.parse_line("X1Y1"))170 m.do_command(GCode.parse_line("X1"))171 self.assertEqual(m.position(), Coordinates(4, 3, 2, 1))172 m.do_command(GCode.parse_line("X-1Y-1Z-1E-1"))173 m.do_command(GCode.parse_line("G90"))174 m.do_command(GCode.parse_line("X1Y1Z1E1"))175 self.assertEqual(m.position(), Coordinates(1, 1, 1, 1))176 def test_g53_g92(self):177 m = GMachine()178 m.do_command(GCode.parse_line("G92X100Y100Z100E100"))179 m.do_command(GCode.parse_line("X101Y102Z103E104"))180 self.assertEqual(m.position(), Coordinates(1, 2, 3, 4))181 m.do_command(GCode.parse_line("G92X-1Y-1Z-1E-1"))182 m.do_command(GCode.parse_line("X1Y1Z1E1"))183 self.assertEqual(m.position(), Coordinates(3, 4, 5, 6))184 m.do_command(GCode.parse_line("G92X3Y4Z5E6"))185 m.do_command(GCode.parse_line("X0Y0Z0E0"))186 self.assertEqual(m.position(), Coordinates(0, 0, 0, 0))187 m.do_command(GCode.parse_line("X1Y2Z3E4"))188 self.assertEqual(m.position(), Coordinates(1, 2, 3, 4))189 m.do_command(GCode.parse_line("G53"))190 m.do_command(GCode.parse_line("X6Y7Z8E9"))191 self.assertEqual(m.position(), Coordinates(6, 7, 8, 9))192 m.do_command(GCode.parse_line("G92E0"))193 m.do_command(GCode.parse_line("X6Y7Z8E1"))194 self.assertEqual(m.position(), Coordinates(6, 7, 8, 10))195 m.do_command(GCode.parse_line("G92"))196 m.do_command(GCode.parse_line("X1Y1Z1E1"))197 self.assertEqual(m.position(), Coordinates(7, 8, 9, 11))198 def test_g53_g91_g92(self):199 m = GMachine()200 m.do_command(GCode.parse_line("G92X-50Y-60Z-70E-80"))201 m.do_command(GCode.parse_line("X-45Y-55Z-65E-75"))202 self.assertEqual(m.position(), Coordinates(5, 5, 5, 5))203 m.do_command(GCode.parse_line("G91"))204 m.do_command(GCode.parse_line("X-1Y-2Z-3E-4"))205 self.assertEqual(m.position(), Coordinates(4, 3, 2, 1))206 def test_m3_m5(self):207 m = GMachine()208 m.do_command(GCode.parse_line("M3S" + str(SPINDLE_MAX_RPM)))209 self.assertRaises(GMachineException,210 m.do_command, GCode.parse_line("M3S-10"))211 self.assertRaises(GMachineException,212 m.do_command, GCode.parse_line("M3S999999999"))213 m.do_command(GCode.parse_line("M5"))214 def test_m104_m109(self):215 m = GMachine()216 m.do_command(GCode.parse_line("M104S"+str(MIN_TEMPERATURE)))217 self.assertEqual(m.extruder_target_temperature(), MIN_TEMPERATURE)218 m.do_command(GCode.parse_line("M104S0"))219 self.assertEqual(m.extruder_target_temperature(), 0)220 # blocking heating should be called with max temperature since virtual221 # hal always return this temperature.222 m.do_command(GCode.parse_line("M109S" + str(EXTRUDER_MAX_TEMPERATURE)))223 self.assertEqual(m.extruder_target_temperature(),224 EXTRUDER_MAX_TEMPERATURE)225 m.do_command(GCode.parse_line("M104S0"))226 self.assertEqual(m.extruder_target_temperature(), 0)227 self.assertRaises(GMachineException, m.do_command,228 GCode.parse_line("M104S"+str(MIN_TEMPERATURE - 1)))229 et = EXTRUDER_MAX_TEMPERATURE + 1230 self.assertRaises(GMachineException, m.do_command,231 GCode.parse_line("M109S" + str(et)))232 self.assertRaises(GMachineException, m.do_command,233 GCode.parse_line("M109"))234 def test_m106_m107(self):235 m = GMachine()236 m.do_command(GCode.parse_line("M106"))237 self.assertTrue(m.fan_state())238 m.do_command(GCode.parse_line("M106S0"))239 self.assertFalse(m.fan_state())240 m.do_command(GCode.parse_line("M106S123"))241 self.assertTrue(m.fan_state())242 m.do_command(GCode.parse_line("M107"))243 self.assertFalse(m.fan_state())244 # check auto fan feature245 m.AUTO_FAN_ON = True246 m.do_command(GCode.parse_line("M104S" + str(MIN_TEMPERATURE)))247 self.assertTrue(m.fan_state())248 m.do_command(GCode.parse_line("M104S0"))249 self.assertTrue(m.fan_state())250 m.do_command(GCode.parse_line("M107"))251 self.assertFalse(m.fan_state())252 m.AUTO_FAN_ON = False253 def test_m140_m190(self):254 m = GMachine()255 m.do_command(GCode.parse_line("M140S"+str(MIN_TEMPERATURE)))256 self.assertEqual(m.bed_target_temperature(), MIN_TEMPERATURE)257 m.do_command(GCode.parse_line("M140S0"))258 self.assertEqual(m.bed_target_temperature(), 0)259 # blocking heating should be called with max temperature since virtual260 # hal always return this temperature.261 m.do_command(GCode.parse_line("M190S" + str(BED_MAX_TEMPERATURE)))262 self.assertEqual(m.bed_target_temperature(), BED_MAX_TEMPERATURE)263 m.do_command(GCode.parse_line("M190S0"))264 self.assertEqual(m.bed_target_temperature(), 0)265 self.assertRaises(GMachineException, m.do_command,266 GCode.parse_line("M140S"+str(MIN_TEMPERATURE - 1)))267 self.assertRaises(GMachineException, m.do_command,268 GCode.parse_line("M190S"269 + str(BED_MAX_TEMPERATURE + 1)))270 self.assertRaises(GMachineException, m.do_command,271 GCode.parse_line("M190"))272if __name__ == '__main__':...

Full Screen

Full Screen

dotenv_test.py

Source:dotenv_test.py Github

copy

Full Screen

...43 # some whitespace checks and a few parts just because44 parsed = self.dotenv.parse('key = value\n\n\n\n name = "bob" # sup\n another = "test\\"value"#okay')45 self.assertEquals({'key': 'value', 'name': 'bob', 'another': 'test"value'}, parsed)46 def test_opening_comment(self):47 self.assertEquals([False, False], self.dotenv.parse_line('# name = test', '#'))48 def test_opening_comment_with_space(self):49 # white space is stripped first, so it still starts with a comment if it has spaces50 self.assertEquals([False, False], self.dotenv.parse_line(' # name = test', '#'))51 def test_any_comment_charater(self):52 # our comment character should be respected53 self.assertEquals([False, False], self.dotenv.parse_line('; name = test', ';'))54 def test_multi_character_comment(self):55 # and it is allowed to be more than one character long56 self.assertEquals([False, False], self.dotenv.parse_line('weirdcomment name = test', 'weirdcomment'))57 def test_ignore_empty_lines(self):58 # empty lines (which includes lines with all white space) are ignored59 self.assertEquals([False, False], self.dotenv.parse_line(' ', '#'))60 def test_invalid_format(self):61 # supported format is something like name = value or name: value62 # if neither of the separators is present then we should get a syntax error63 self.assertRaises(DotEnvSyntaxError, self.dotenv.parse_line, 'sup', '#')64 def test_empty_value_equal(self):65 # empty values are allowed66 self.assertEquals(['key', ''], self.dotenv.parse_line('key=', '#'))67 def test_empty_value_colon(self):68 # colons act exactly the same way69 self.assertEquals(['key', ''], self.dotenv.parse_line('key:', '#'))70 def test_empty_value_equal_spaces(self):71 # and spaces are ignored72 self.assertEquals(['key', ''], self.dotenv.parse_line(" key \t=\t ", '#'))73 def test_empty_value_equal_colon(self):74 # and spaces are ignored75 self.assertEquals(['key', ''], self.dotenv.parse_line(" key \t:\t ", '#'))76 def test_value_no_quotes_equal(self):77 # a value without quotes should be easy78 self.assertEquals(['key', 'asdf'], self.dotenv.parse_line("key=asdf", '#'))79 def test_value_no_quotes_colon(self):80 # a value without quotes should be easy81 self.assertEquals(['key', 'asdf'], self.dotenv.parse_line("key:asdf", '#'))82 def test_value_no_quotes_equal_spaces(self):83 # spaces are still ignored at the beginning/end of a part84 self.assertEquals(['key', 'asdf bob'], self.dotenv.parse_line("key= asdf bob \t", '#'))85 def test_value_no_quotes_equal_colon(self):86 # spaces are still ignored at the beginning/end of a part87 self.assertEquals(['key', 'asdf bob'], self.dotenv.parse_line("key : asdf bob \t", '#'))88 def test_value_no_quotes_equal_comment(self):89 # and comments at the end are ignored (including spaces before comments)90 self.assertEquals(['key', 'asdf bob'], self.dotenv.parse_line("key = asdf bob \t# a comment", '#'))91 def test_value_no_quotes_equal_colon(self):92 # and comments at the end are ignored (including spaces before comments)93 self.assertEquals(['key', 'asdf bob'], self.dotenv.parse_line("key : asdf bob \t; a comment", ';'))94 def test_no_lone_quotes_double(self):95 # a quote character inside the value by itself is invalid96 self.assertRaises(DotEnvSyntaxError, self.dotenv.parse_line, 'name = valu"e', '#')97 def test_no_lone_quotes_single(self):98 # a quote character inside the value by itself is invalid99 self.assertRaises(DotEnvSyntaxError, self.dotenv.parse_line, "name = valu'e", '#')100 def test_empty_single(self):101 # easy102 self.assertEquals(['db', ''], self.dotenv.parse_line("db = ''", '#'))103 def test_empty_double(self):104 # easy105 self.assertEquals(['db', ''], self.dotenv.parse_line('db = ""', '#'))106 def test_empty_single_comment(self):107 # easy108 self.assertEquals(['db', ''], self.dotenv.parse_line("db = '' # database name", '#'))109 def test_empty_double_comment(self):110 # easy111 self.assertEquals(['db', ''], self.dotenv.parse_line('db = "" ; database name', ';'))112 def test_single_quotes(self):113 # I shouldn't get the quotes back. Also white space should114 # be ignored still115 self.assertEquals(['db', 'dijere'], self.dotenv.parse_line("db = 'dijere' ", '#'))116 def test_double_quotes(self):117 # I shouldn't get the quotes back. Also white space should118 # be ignored still119 self.assertEquals(['db', 'dijere'], self.dotenv.parse_line('db = "dijere" ', '#'))120 def test_no_closing_quote_single(self):121 # syntax error if we have an opening quote with no close122 self.assertRaises(DotEnvSyntaxError, self.dotenv.parse_line, "name = 'test", '#')123 def test_no_closing_quote_double(self):124 # syntax error if we have an opening quote with no close125 self.assertRaises(DotEnvSyntaxError, self.dotenv.parse_line, 'name = "test', '#')126 def test_double_quotes_with_comment(self):127 # comments after the quotes should be ignored (along with whitespace)128 self.assertEquals(['db', 'bob'], self.dotenv.parse_line('db = "bob" ; database name', ';'))129 def test_single_quotes_with_comment(self):130 # comments after the quotes should be ignored (along with whitespace)131 self.assertEquals(['db', 'bob'], self.dotenv.parse_line("db = 'bob' \t# database name", '#'))132 def test_text_outside_of_double(self):133 # anything outside of the quotes and before a comment results in a syntax error134 self.assertRaises(DotEnvSyntaxError, self.dotenv.parse_line, 'name = "test" sup # hey', '#')135 def test_text_outside_of_single(self):136 # anything outside of the quotes and before a comment results in a syntax error137 self.assertRaises(DotEnvSyntaxError, self.dotenv.parse_line, "name = 'test' sup ; hey", ';')138 def test_allow_ending_semicolon(self):139 # anything outside of the quotes and before a comment results in a syntax error140 # except allow to end the line with a semi-colon.141 self.assertEquals(['name', 'test'], self.dotenv.parse_line("name = 'test';", '#'))142 def test_escaped_single_quote(self):143 # quotes can be escaped inside quotes144 self.assertEquals(['db', "asdf'qwerty'"], self.dotenv.parse_line("db = 'asdf\\'qwerty\\''", '#'))145 def test_escaped_double_quote(self):146 # quotes can be escaped inside quotes147 self.assertEquals(['db', 'asdf"qwerty"'], self.dotenv.parse_line('db = "asdf\\"qwerty\\""', '#'))148 def test_preserve_other_slashes(self):149 # other slashes are left alone150 self.assertEquals(['db', 'asdf\\bob'], self.dotenv.parse_line('db = "asdf\\bob"', '#'))151 def test_double_quote_in_single_quote(self):152 # double quote inside single quotes are just regular characters153 self.assertEquals(['db', 'asdf"bob'], self.dotenv.parse_line("db = 'asdf\"bob'", '#'))154 def test_single_quote_in_double_quote(self):155 # single quote inside double quotes are just regular characters...

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