From 1106819e426fc0408b44f7987af82d75d7fa0d65 Mon Sep 17 00:00:00 2001 From: Andrew Hamilton Date: Wed, 10 Feb 2016 19:30:30 +0000 Subject: [PATCH] Added the disassemble_pyc tool. --- TODO | 4 ++-- golden-files/input/hi3.cpython-34.pyc | Bin 0 -> 208 bytes tools.py | 3 ++- tools_test.py | 4 ++++ 4 files changed, 8 insertions(+), 3 deletions(-) create mode 100644 golden-files/input/hi3.cpython-34.pyc diff --git a/TODO b/TODO index af6733f..f2c6001 100644 --- a/TODO +++ b/TODO @@ -1,5 +1,4 @@ Todo -- Test the tools. - Publish. pypi and github will do. - docs?, setup.py?, wheel?, __pkginfo__.py? - Maybe also use cxfreeze, py2exe, pyrun or zipapp? Is zipapp the standard way? @@ -159,7 +158,8 @@ Done - Don't let the user scroll indefinately below the end of the page. - Add command line options, e.g. -h - Boilerplate: Readme, usage - +- Test the tools. + <- All the existing tools now have basic tests. A-syntax, B-tests, C-auto docs, D-lint, E-coverage, F-profile, G-tidy, H-import deps A B C D E F G H diff --git a/golden-files/input/hi3.cpython-34.pyc b/golden-files/input/hi3.cpython-34.pyc new file mode 100644 index 0000000000000000000000000000000000000000..ee2fac47c6ceff24c13d0d26b23bbefe3560a0fd GIT binary patch literal 208 zcmaFI!^<^;c}tiK0|UcjAcg}bAj<)Wiv@s03J@_ev@kG40U1mT!J5p;Kv6gVsdWb8 zVm=^I0#@71$iN8H6|BkRcZ(?_QF!75|Pd_uSptM9kBhy%~ rpt6V&CPO2SP7f2HTAyyxX literal 0 HcmV?d00001 diff --git a/tools.py b/tools.py index 3fb69b8..d8e7d3f 100644 --- a/tools.py +++ b/tools.py @@ -396,7 +396,8 @@ def python_tidy(path): # Deps: found on internet? def disassemble_pyc(path): - bytecode = open(path, "rb").read() + with open(path, "rb") as file_: + bytecode = file_.read() stringio = io.StringIO() dis.dis(bytecode, file=stringio) stringio.seek(0) diff --git a/tools_test.py b/tools_test.py index b4c036d..54829f5 100755 --- a/tools_test.py +++ b/tools_test.py @@ -106,6 +106,10 @@ class ToolsTestCase(unittest.TestCase): def test_python_mccable(self): self._test_tool(tools.python_mccabe, self.HI_OK) + def test_disassemble_pyc(self): + self._test_tool(tools.disassemble_pyc, + [("hi3.cpython-34.pyc", tools.Status.normal)]) + def test_perl_syntax(self): self._test_tool(tools.perl_syntax, [("perl.pl", tools.Status.ok)])