def test_post_command_comment_with_multiple_spaces(self): listing = html.fromstring( '<div class="listingblock">' '<div class="content">' '<pre><code>$ <strong>git diff</strong> # should show changes to functional_tests.py\n' '$ <strong>git commit -am "Functional test now checks we can input a to-do item"</strong></code></pre>' '</div></div> ' ) commands = get_commands(listing) self.assertEqual( commands, [ 'git diff', 'git commit -am "Functional test now checks we can input a to-do item"', ] ) parsed_listings = parse_listing(listing) self.assertEqual( parsed_listings, [ 'git diff', ' # should show changes to functional_tests.py', 'git commit -am "Functional test now checks we can input a to-do item"', ] ) self.assertEqual(type(parsed_listings[0]), Command) self.assertEqual(type(parsed_listings[1]), Output) self.assertEqual(type(parsed_listings[2]), Command)
def test_extracting_multiple(self): listing = html.fromstring( '<div class="listingblock">\r\n<div class="content">\r\n<pre><code>$ <strong>ls</strong>\r\nsuperlists functional_tests.py\r\n$ <strong>mv functional_tests.py superlists/</strong>\r\n$ <strong>cd superlists</strong>\r\n$ <strong>git init .</strong>\r\nInitialized empty Git repository in /chapter_1/superlists/.git/</code></pre>\r\n</div></div> \n' ) self.assertEqual( get_commands(listing), ["ls", "mv functional_tests.py superlists/", "cd superlists", "git init ."] )
def test_post_command_comment_with_multiple_spaces(self): listing = html.fromstring( '<div class="listingblock">' '<div class="content">' "<pre><code>$ <strong>git diff</strong> # should show changes to functional_tests.py\n" '$ <strong>git commit -am "Functional test now checks we can input a to-do item"</strong></code></pre>' "</div></div> " ) commands = get_commands(listing) self.assertEqual( commands, ["git diff", 'git commit -am "Functional test now checks we can input a to-do item"'] ) parsed_listings = parse_listing(listing) self.assertEqual( parsed_listings, [ "git diff", " # should show changes to functional_tests.py", 'git commit -am "Functional test now checks we can input a to-do item"', ], ) self.assertEqual(type(parsed_listings[0]), Command) self.assertEqual(type(parsed_listings[1]), Output) self.assertEqual(type(parsed_listings[2]), Command)
def test_extracting_one_command(self): listing = html.fromstring( '<div class="listingblock">\r\n<div class="content">\r\n<pre><code>$ <strong>python3 functional_tests.py</strong>\r\nTraceback (most recent call last):\r\n File "functional_tests.py", line 6, in <module>\r\n assert \'Django\' in browser.title\r\nAssertionError</code></pre>\r\n</div></div> \n' ) self.assertEqual( get_commands(listing), ['python3 functional_tests.py'] )
def test_extracting_multiple(self): listing = html.fromstring( '<div class="listingblock">\r\n<div class="content">\r\n<pre><code>$ <strong>ls</strong>\r\nsuperlists functional_tests.py\r\n$ <strong>mv functional_tests.py superlists/</strong>\r\n$ <strong>cd superlists</strong>\r\n$ <strong>git init .</strong>\r\nInitialized empty Git repository in /chapter_1/superlists/.git/</code></pre>\r\n</div></div> \n' # noqa ) self.assertEqual(get_commands(listing), [ 'ls', 'mv functional_tests.py superlists/', 'cd superlists', 'git init .', ])
def test_handles_inline_inputs(self): listing = html.fromstring(examples.OUTPUT_WITH_COMMANDS_INLINE) commands = get_commands(listing) self.assertEqual([str(c) for c in commands], ["python manage.py makemigrations", "1", "''"]) # too hard for now parsed_listings = parse_listing(listing) print(parsed_listings) self.assertEqual(type(parsed_listings[0]), Command) self.assertEqual(parsed_listings[0], commands[0]) print(parsed_listings[1]) self.assertIn("Select an option:", parsed_listings[1]) self.assertTrue(parsed_listings[1].endswith("Select an option: "))
def test_handles_inline_inputs(self): listing = html.fromstring(examples.OUTPUT_WITH_COMMANDS_INLINE) commands = get_commands(listing) self.assertEqual([str(c) for c in commands], [ 'python manage.py makemigrations', '1', "''", ]) # too hard for now parsed_listings = parse_listing(listing) print(parsed_listings) self.assertEqual(type(parsed_listings[0]), Command) self.assertEqual(parsed_listings[0], commands[0]) print(parsed_listings[1]) self.assertIn('Select an option:', parsed_listings[1]) self.assertTrue(parsed_listings[1].endswith('Select an option: '))
def test_handles_multiline_commands(self): listing = html.fromstring( dedent(""" <div class="listingblock"> <div class="content"> <pre><code>$ <strong>do something\\ that continues on this line</strong> OK </code></pre> </div></div> """)) commands = get_commands(listing) assert len(commands) == 1 #assert commands[0] == 'do something\\\nthat continues on this line' assert commands[0] == 'do somethingthat continues on this line' # too hard for now parsed_listings = parse_listing(listing) print(parsed_listings) self.assertEqual(type(parsed_listings[0]), Command) self.assertEqual(parsed_listings[0], commands[0])
def test_handles_multiline_commands(self): listing = html.fromstring(dedent( """ <div class="listingblock"> <div class="content"> <pre><code>$ <strong>do something\\ that continues on this line</strong> OK </code></pre> </div></div> """ )) commands = get_commands(listing) assert len(commands) == 1 #assert commands[0] == 'do something\\\nthat continues on this line' assert commands[0] == 'do somethingthat continues on this line' # too hard for now parsed_listings = parse_listing(listing) print(parsed_listings) self.assertEqual(type(parsed_listings[0]), Command) self.assertEqual(parsed_listings[0], commands[0])