-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add width attribute #8
Open
Utkarsh1308
wants to merge
1
commit into
juhakivekas:master
Choose a base branch
from
Utkarsh1308:width
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
0123456789abcdef012345678 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
0123456789abcdef |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
from multidiff.Render import * | ||
from multidiff import Ansi | ||
|
||
import unittest | ||
from pathlib import Path | ||
import subprocess | ||
|
||
|
||
class MainCLITests(unittest.TestCase): | ||
Utkarsh1308 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
def call_run(self, expected_stdout, args): | ||
got_stdout = '(no stdout)' | ||
cmd = ['multidiff'] + args | ||
try: | ||
got_stdout = subprocess.check_output(cmd, universal_newlines=True) | ||
except subprocess.CalledProcessError as err: | ||
print('Got stderr: `{err_message}`'.format(err_message=err)) | ||
finally: | ||
print('Got stdout: `{stdout}`'.format(stdout=got_stdout)) | ||
|
||
self.assertEqual(expected_stdout, got_stdout) | ||
|
||
def test_diff_cli_no_args(self): | ||
expected_output = '' | ||
self.call_run(expected_output, []) | ||
|
||
def test_diff_cli_simple(self): | ||
p = Path(".") | ||
res = list(p.glob("**/bin_file*")) | ||
res = [str(x) for x in res] | ||
|
||
dump = Ansi.bold + res[1] + Ansi.reset | ||
dump += "\n000000: " | ||
dump += "30 31 32 33 34 35 36 37 38 39 61 62 63 64 65 66" | ||
dump += Ansi.delete + " " + Ansi.reset | ||
dump += "|0123456789abcdef|\n" | ||
|
||
expected_output = dump | ||
self.call_run(expected_output, res) | ||
|
||
def test_diff_cli_with_width_flag(self): | ||
p = Path('.') | ||
res = res = list(p.glob('**/bin_file*')) | ||
res = [str(x) for x in res] | ||
res += ['--width', '25'] | ||
|
||
dump = Ansi.bold + res[1] + Ansi.reset | ||
dump += "\n000000: " | ||
dump += "30 31 32 33 34 35 36 37" | ||
dump += "\n38 39 61 62 63 64 65" | ||
dump += "\n66" | ||
dump += Ansi.delete + " " + Ansi.reset | ||
dump += "|0123456789abcdef|\n" | ||
|
||
expected_output = dump | ||
self.call_run(expected_output, res) | ||
|
||
def test_diff_cli_with_bytes_flag(self): | ||
p = Path('.') | ||
res = res = list(p.glob('**/bin_file*')) | ||
res = [str(x) for x in res] | ||
res += ['--bytes', '6'] | ||
|
||
dump = Ansi.bold + res[1] + Ansi.reset | ||
dump += "\n000000: " | ||
dump += "30 31 32 33 34 35" | ||
dump += ' |012345|' | ||
dump += "\n000006: " | ||
dump += "36 37 38 39 61 62" | ||
dump += ' |6789ab|' | ||
dump += "\n00000c: " | ||
dump += "63 64 65 66" | ||
dump += Ansi.delete + " " + Ansi.reset | ||
dump += ' |cdef|' | ||
dump += '\n\n' | ||
print(dump) | ||
|
||
expected_output = dump | ||
self.call_run(expected_output, res) | ||
|
||
if __name__ == '__main__': | ||
unittest.main() |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't need to be this complicated. Just find the number
16
from Render.py and make it not hardcoded. For example replace all occurencies of16
withself.bytewidth
and set that variable when constructing theRender
object. This way there's no need to compile the regular expressions, find strings and do all the reformatting that takes a lot of time (you mentioned this was an issue?). As a side effect the format (addresses, ascii conversion etc.) will match the originalThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. I tried the approach you are suggesting first but then the code runs slowly on my machine. I don't know if it's a problem with my machine or not. Please tell me if by changing those lines the code runs the same in your machine. I would be happy to implement that since it's easier :)