From 334e71239ae0b295aa4c7969a3048c1d23cb164d Mon Sep 17 00:00:00 2001 From: Rohit Sanjay Date: Sat, 3 Aug 2024 17:56:05 -0700 Subject: [PATCH] single quote --- docs/conf.py | 68 ++++++++--------- examples/dataframe-example/dataframe_test.py | 8 +- examples/requests-example/requests_test.py | 10 +-- examples/stdout-example/stdout_test.py | 6 +- pyproject.toml | 3 +- testbook/client.py | 78 ++++++++++---------- testbook/reference.py | 20 ++--- testbook/testbook.py | 2 +- testbook/testbooknode.py | 14 ++-- testbook/tests/conftest.py | 18 ++--- testbook/tests/test_client.py | 64 ++++++++-------- testbook/tests/test_datamodel.py | 40 +++++----- testbook/tests/test_execute.py | 46 ++++++------ testbook/tests/test_inject.py | 38 +++++----- testbook/tests/test_patch.py | 16 ++-- testbook/tests/test_reference.py | 32 ++++---- testbook/tests/test_testbook.py | 36 ++++----- testbook/tests/test_translators.py | 48 ++++++------ testbook/translators.py | 34 ++++----- testbook/utils.py | 2 +- 20 files changed, 291 insertions(+), 292 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index f414996..f643a14 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -15,14 +15,14 @@ from importlib.metadata import version as read_version -sys.path.insert(0, os.path.abspath("..")) +sys.path.insert(0, os.path.abspath('..')) # -- Project information ----------------------------------------------------- -project = "testbook" -copyright = "2024, nteract team" -author = "nteract team" +project = 'testbook' +copyright = '2024, nteract team' +author = 'nteract team' # -- General configuration --------------------------------------------------- @@ -31,28 +31,28 @@ # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom # ones. extensions = [ - "sphinx.ext.autodoc", - "sphinx.ext.intersphinx", - "sphinx.ext.mathjax", - "sphinx.ext.napoleon", - "myst_parser", + 'sphinx.ext.autodoc', + 'sphinx.ext.intersphinx', + 'sphinx.ext.mathjax', + 'sphinx.ext.napoleon', + 'myst_parser', ] # Add any paths that contain templates here, relative to this directory. -templates_path = ["_templates"] +templates_path = ['_templates'] # The suffix(es) of source filenames. # You can specify multiple suffix as a list of string: # -source_suffix = [".rst", ".md"] +source_suffix = ['.rst', '.md'] # The master toctree document. -master_doc = "index" +master_doc = 'index' # General information about the project. -project = "testbook" -copyright = "2024, nteract team" -author = "nteract team" +project = 'testbook' +copyright = '2024, nteract team' +author = 'nteract team' # The version info for the project you're documenting, acts as replacement for # |version| and |release|, also used in various other places throughout the @@ -61,7 +61,7 @@ # The short X.Y version. -version = '.'.join(read_version(project).split(".")[0:2]) +version = '.'.join(read_version(project).split('.')[0:2]) # The full version, including alpha/beta/rc tags. release = read_version(project) @@ -71,15 +71,15 @@ # # This is also used if you do content translation via gettext catalogs. # Usually you set "language" from the command line foexitr these cases. -language = "en" +language = 'en' # List of patterns, relative to source directory, that match files and # directories to ignore when looking for source files. # This patterns also effect to html_static_path and html_extra_path -exclude_patterns = ["_build", "Thumbs.db", ".DS_Store", "UPDATE.md"] +exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store', 'UPDATE.md'] # The name of the Pygments (syntax highlighting) style to use. -pygments_style = "sphinx" +pygments_style = 'sphinx' # If true, `todo` and `todoList` produce output, else they produce nothing. todo_include_todos = False @@ -90,7 +90,7 @@ # The theme to use for HTML and HTML Help pages. See the documentation for # a list of builtin themes. # -html_theme = "sphinx_book_theme" +html_theme = 'sphinx_book_theme' # Theme options are theme-specific and customize the look and feel of a theme # further. For a list of options available for each theme, see the @@ -98,10 +98,10 @@ # html_theme_options = { - "path_to_docs": "docs", - "repository_url": "https://github.com/nteract/testbook", - "repository_branch": "main", - "use_edit_page_button": True, + 'path_to_docs': 'docs', + 'repository_url': 'https://github.com/nteract/testbook', + 'repository_branch': 'main', + 'use_edit_page_button': True, } # Add any paths that contain custom static files (such as style sheets) here, @@ -109,12 +109,12 @@ # so a file named "default.css" will overwrite the builtin "default.css". # html_static_path = ['_static'] -html_title = "testbook" +html_title = 'testbook' # -- Options for HTMLHelp output ------------------------------------------ # Output file base name for HTML help builder. -htmlhelp_basename = "testbookdoc" +htmlhelp_basename = 'testbookdoc' # -- Options for LaTeX output --------------------------------------------- @@ -138,7 +138,7 @@ # (source start file, target name, title, # author, documentclass [howto, manual, or own class]). latex_documents = [ - (master_doc, "testbook.tex", "testbook Documentation", "nteract team", "manual") + (master_doc, 'testbook.tex', 'testbook Documentation', 'nteract team', 'manual') ] @@ -146,7 +146,7 @@ # One entry per manual page. List of tuples # (source start file, name, description, authors, manual section). -man_pages = [(master_doc, "testbook", "testbook Documentation", [author], 1)] +man_pages = [(master_doc, 'testbook', 'testbook Documentation', [author], 1)] # -- Options for Texinfo output ------------------------------------------- @@ -157,17 +157,17 @@ texinfo_documents = [ ( master_doc, - "testbook", - "testbook Documentation", + 'testbook', + 'testbook Documentation', author, - "testbook", - "One line description of project.", - "Miscellaneous", + 'testbook', + 'One line description of project.', + 'Miscellaneous', ) ] # Example configuration for intersphinx: refer to the Python standard library. -intersphinx_mapping = {"python": ("https://docs.python.org/", None)} +intersphinx_mapping = {'python': ('https://docs.python.org/', None)} # Generate heading anchors for h1, h2 and h3. myst_heading_anchors = 3 diff --git a/examples/dataframe-example/dataframe_test.py b/examples/dataframe-example/dataframe_test.py index fa2ffbe..4c10181 100644 --- a/examples/dataframe-example/dataframe_test.py +++ b/examples/dataframe-example/dataframe_test.py @@ -1,9 +1,9 @@ from testbook import testbook -@testbook("./dataframe-assertion-example.ipynb") +@testbook('./dataframe-assertion-example.ipynb') def test_dataframe_manipulation(tb): - tb.execute_cell("imports") + tb.execute_cell('imports') # Inject a dataframe with code tb.inject( @@ -13,7 +13,7 @@ def test_dataframe_manipulation(tb): ) # Perform manipulation - tb.execute_cell("manipulation") + tb.execute_cell('manipulation') # Inject assertion into notebook - tb.inject("assert len(df) == 1") + tb.inject('assert len(df) == 1') diff --git a/examples/requests-example/requests_test.py b/examples/requests-example/requests_test.py index 49c1757..49bd633 100644 --- a/examples/requests-example/requests_test.py +++ b/examples/requests-example/requests_test.py @@ -1,10 +1,10 @@ from testbook import testbook -@testbook("./requests-test.ipynb", execute=True) +@testbook('./requests-test.ipynb', execute=True) def test_get_details(tb): - with tb.patch("requests.get") as mock_get: - get_details = tb.ref("get_details") # get reference to function - get_details("https://my-api.com") + with tb.patch('requests.get') as mock_get: + get_details = tb.ref('get_details') # get reference to function + get_details('https://my-api.com') - mock_get.assert_called_with("https://my-api.com") + mock_get.assert_called_with('https://my-api.com') diff --git a/examples/stdout-example/stdout_test.py b/examples/stdout-example/stdout_test.py index ead54fb..95c0d51 100644 --- a/examples/stdout-example/stdout_test.py +++ b/examples/stdout-example/stdout_test.py @@ -1,8 +1,8 @@ from testbook import testbook -@testbook("stdout-assertion-example.ipynb", execute=True) +@testbook('stdout-assertion-example.ipynb', execute=True) def test_stdout(tb): - assert tb.cell_output_text(1) == "hello world!" + assert tb.cell_output_text(1) == 'hello world!' - assert "The current time is" in tb.cell_output_text(2) + assert 'The current time is' in tb.cell_output_text(2) diff --git a/pyproject.toml b/pyproject.toml index 33e9110..fdd0f68 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -148,8 +148,7 @@ unfixable = [] dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$" [tool.ruff.format] -# Like Black, use double quotes for strings. -quote-style = "double" +quote-style = "single" # Like Black, indent with spaces, rather than tabs. indent-style = "space" diff --git a/testbook/client.py b/testbook/client.py index 8e5c9c9..639ce64 100644 --- a/testbook/client.py +++ b/testbook/client.py @@ -25,13 +25,13 @@ class TestbookNotebookClient(NotebookClient): def __init__(self, nb, km=None, **kw): # Fix the ipykernel 5.5 issue where execute requests after errors are aborted - ea = kw.get("extra_arguments", []) + ea = kw.get('extra_arguments', []) if not any( - arg.startswith("--Kernel.stop_on_error_timeout") + arg.startswith('--Kernel.stop_on_error_timeout') for arg in self.extra_arguments ): - ea.append("--Kernel.stop_on_error_timeout=0") - kw["extra_arguments"] = ea + ea.append('--Kernel.stop_on_error_timeout=0') + kw['extra_arguments'] = ea super().__init__(nb, km=km, **kw) def ref(self, name: str) -> Union[TestbookObjectReference, Any]: @@ -42,7 +42,7 @@ def ref(self, name: str) -> Union[TestbookObjectReference, Any]: # Check if exists self.inject(name, pop=True) try: - self.inject(f"import json; json.dumps({name})", pop=True) + self.inject(f'import json; json.dumps({name})', pop=True) return self.value(name) except Exception: return TestbookObjectReference(self, name) @@ -81,22 +81,22 @@ def _execute_result(cell) -> List: """ return [ - output["data"] - for output in cell["outputs"] - if output["output_type"] == "execute_result" + output['data'] + for output in cell['outputs'] + if output['output_type'] == 'execute_result' ] @staticmethod def _output_text(cell) -> str: - if "outputs" not in cell: - raise ValueError("cell must be a code cell") + if 'outputs' not in cell: + raise ValueError('cell must be a code cell') - text = "" - for output in cell["outputs"]: - if "text" in output: - text += output["text"] - elif "data" in output and "text/plain" in output["data"]: - text += output["data"]["text/plain"] + text = '' + for output in cell['outputs']: + if 'text' in output: + text += output['text'] + elif 'data' in output and 'text/plain' in output['data']: + text += output['data']['text/plain'] return text.strip() @@ -108,11 +108,11 @@ def _cell_index(self, tag: Union[int, str]) -> int: if isinstance(tag, int): return tag elif not isinstance(tag, str): - raise TypeError("expected tag as str") + raise TypeError('expected tag as str') for idx, cell in enumerate(self.cells): - metadata = cell["metadata"] - if "tags" in metadata and tag in metadata["tags"]: + metadata = cell['metadata'] + if 'tags' in metadata and tag in metadata['tags']: return idx raise TestbookCellTagNotFoundError("Cell tag '{}' not found".format(tag)) @@ -124,7 +124,7 @@ def execute_cell(self, cell, **kwargs) -> Union[Dict, List[Dict]]: if isinstance(cell, slice): start, stop = self._cell_index(cell.start), self._cell_index(cell.stop) if cell.step is not None: - raise TestbookError("testbook does not support step argument") + raise TestbookError('testbook does not support step argument') cell = range(start, stop + 1) elif isinstance(cell, str) or isinstance(cell, int): @@ -138,7 +138,7 @@ def execute_cell(self, cell, **kwargs) -> Union[Dict, List[Dict]]: executed_cells = [] for idx in cell_indexes: try: - cell = super().execute_cell(self.nb["cells"][idx], idx, **kwargs) + cell = super().execute_cell(self.nb['cells'][idx], idx, **kwargs) except CellExecutionError as ce: raise TestbookRuntimeError( ce.evalue, ce, self._get_error_class(ce.ename) @@ -161,7 +161,7 @@ def cell_output_text(self, cell) -> str: Return cell text output """ cell_index = self._cell_index(cell) - return self._output_text(self.nb["cells"][cell_index]) + return self._output_text(self.nb['cells'][cell_index]) def cell_execute_result(self, cell: Union[int, str]) -> List[Dict[str, Any]]: """Return the execute results of cell at a given index or with a given tag. @@ -188,7 +188,7 @@ def cell_execute_result(self, cell: Union[int, str]) -> List[Dict[str, Any]]: If tag is not found """ cell_index = self._cell_index(cell) - return self._execute_result(self.nb["cells"][cell_index]) + return self._execute_result(self.nb['cells'][cell_index]) def inject( self, @@ -229,15 +229,15 @@ def inject( lines = getsource(code) + ( dedent(self._construct_call_code(code.__name__, args, kwargs)) if run - else "" + else '' ) else: - raise TypeError("can only inject function or code block as str") + raise TypeError('can only inject function or code block as str') inject_idx = len(self.cells) if after is not None and before is not None: - raise ValueError("pass either before or after as kwargs") + raise ValueError('pass either before or after as kwargs') elif before is not None: inject_idx = self._cell_index(before) elif after is not None: @@ -253,8 +253,8 @@ def inject( ) if self._contains_error(cell): - eclass = self._get_error_class(cell.get("outputs")[0]["ename"]) - evalue = cell.get("outputs")[0]["evalue"] + eclass = self._get_error_class(cell.get('outputs')[0]['ename']) + evalue = cell.get('outputs')[0]['evalue'] raise TestbookRuntimeError(evalue, evalue, eclass) if run and pop: @@ -290,7 +290,7 @@ def value(self, code: str) -> Any: if not self._execute_result(result): raise TestbookExecuteResultNotFoundError( - "code provided does not produce execute_result" + 'code provided does not produce execute_result' ) save_varname = random_varname() @@ -309,24 +309,24 @@ def value(self, code: str) -> Any: try: outputs = self.inject(inject_code, pop=True).outputs - if outputs[0].output_type == "error": + if outputs[0].output_type == 'error': # will receive error when `allow_errors` is set to True raise TestbookRuntimeError( outputs[0].evalue, outputs[0].traceback, outputs[0].ename ) - return outputs[0].data["application/json"]["value"] + return outputs[0].data['application/json']['value'] except TestbookRuntimeError: - e = TestbookSerializeError("could not JSON serialize output") + e = TestbookSerializeError('could not JSON serialize output') e.save_varname = save_varname raise e @contextmanager def patch(self, target, **kwargs): """Used as contextmanager to patch objects in the kernel""" - mock_object = f"_mock_{random_varname()}" - patcher = f"_patcher_{random_varname()}" + mock_object = f'_mock_{random_varname()}' + patcher = f'_patcher_{random_varname()}' self.inject( f""" @@ -341,13 +341,13 @@ def patch(self, target, **kwargs): yield TestbookObjectReference(self, mock_object) - self.inject(f"{patcher}.stop()") + self.inject(f'{patcher}.stop()') @contextmanager def patch_dict(self, in_dict, values=(), clear=False, **kwargs): """Used as contextmanager to patch dictionaries in the kernel""" - mock_object = f"_mock_{random_varname()}" - patcher = f"_patcher_{random_varname()}" + mock_object = f'_mock_{random_varname()}' + patcher = f'_patcher_{random_varname()}' self.inject( f""" @@ -364,7 +364,7 @@ def patch_dict(self, in_dict, values=(), clear=False, **kwargs): yield TestbookObjectReference(self, mock_object) - self.inject(f"{patcher}.stop()") + self.inject(f'{patcher}.stop()') @staticmethod def _get_error_class(ename): @@ -377,4 +377,4 @@ def _get_error_class(ename): @staticmethod def _contains_error(result): - return result.get("outputs") and result.get("outputs")[0].output_type == "error" + return result.get('outputs') and result.get('outputs')[0].output_type == 'error' diff --git a/testbook/reference.py b/testbook/reference.py index 89ead9a..3a0b0c6 100644 --- a/testbook/reference.py +++ b/testbook/reference.py @@ -15,27 +15,27 @@ def __init__(self, tb, name): @property def _type(self): - return self.tb.value(f"type({self.name}).__name__") + return self.tb.value(f'type({self.name}).__name__') def __repr__(self): - return repr(self.tb.value(f"repr({self.name})")) + return repr(self.tb.value(f'repr({self.name})')) def __getattr__(self, name): if self.tb.value(f"hasattr({self.name}, '{name}')"): - return TestbookObjectReference(self.tb, f"{self.name}.{name}") + return TestbookObjectReference(self.tb, f'{self.name}.{name}') raise TestbookAttributeError(f"'{self._type}' object has no attribute {name}") def __eq__(self, rhs): return self.tb.value( - "{lhs} == {rhs}".format(lhs=self.name, rhs=PythonTranslator.translate(rhs)) + '{lhs} == {rhs}'.format(lhs=self.name, rhs=PythonTranslator.translate(rhs)) ) def __len__(self): - return self.tb.value(f"len({self.name})") + return self.tb.value(f'len({self.name})') def __iter__(self): - iterobjectname = f"___iter_object_{random_varname()}" + iterobjectname = f'___iter_object_{random_varname()}' self.tb.inject(f""" {iterobjectname} = iter({self.name}) """) @@ -43,7 +43,7 @@ def __iter__(self): def __next__(self): try: - return self.tb.value(f"next({self.name})") + return self.tb.value(f'next({self.name})') except TestbookRuntimeError as e: if e.eclass is StopIteration: raise StopIteration @@ -53,7 +53,7 @@ def __next__(self): def __getitem__(self, key): try: return self.tb.value( - f"{self.name}.__getitem__({PythonTranslator.translate(key)})" + f'{self.name}.__getitem__({PythonTranslator.translate(key)})' ) except TestbookRuntimeError as e: if e.eclass is TypeError: @@ -66,7 +66,7 @@ def __getitem__(self, key): def __setitem__(self, key, value): try: return self.tb.inject( - "{name}[{key}] = {value}".format( + '{name}[{key}] = {value}'.format( name=self.name, key=PythonTranslator.translate(key), value=PythonTranslator.translate(value), @@ -83,7 +83,7 @@ def __setitem__(self, key, value): def __contains__(self, item): return self.tb.value( - f"{self.name}.__contains__({PythonTranslator.translate(item)})" + f'{self.name}.__contains__({PythonTranslator.translate(item)})' ) def __call__(self, *args, **kwargs): diff --git a/testbook/testbook.py b/testbook/testbook.py index ebe10af..d70000b 100644 --- a/testbook/testbook.py +++ b/testbook/testbook.py @@ -32,7 +32,7 @@ def __init__( nb, execute=None, timeout=60, - kernel_name="python3", + kernel_name='python3', allow_errors=False, **kwargs, ): diff --git a/testbook/testbooknode.py b/testbook/testbooknode.py index b39fd66..9a3e2af 100644 --- a/testbook/testbooknode.py +++ b/testbook/testbooknode.py @@ -11,10 +11,10 @@ def __init__(self, *args, **kw): @property def output_text(self) -> str: - text = "" - for output in self["outputs"]: - if "text" in output: - text += output["text"] + text = '' + for output in self['outputs']: + if 'text' in output: + text += output['text'] return text.strip() @@ -22,7 +22,7 @@ def output_text(self) -> str: def execute_result(self): """Return data from execute_result outputs""" return [ - output["data"] - for output in self["outputs"] - if output["output_type"] == "execute_result" + output['data'] + for output in self['outputs'] + if output['output_type'] == 'execute_result' ] diff --git a/testbook/tests/conftest.py b/testbook/tests/conftest.py index c6fbd7c..68fcff0 100644 --- a/testbook/tests/conftest.py +++ b/testbook/tests/conftest.py @@ -20,10 +20,10 @@ def notebook_generator(cells: Optional[List[NotebookNode]] = None) -> NotebookNo for name in kernelspec.find_kernel_specs(): ks = kernelspec.get_kernel_spec(name) metadata = { - "kernelspec": { - "name": name, - "language": ks.language, - "display_name": ks.display_name, + 'kernelspec': { + 'name': name, + 'language': ks.language, + 'display_name': ks.display_name, } } break @@ -32,12 +32,12 @@ def notebook_generator(cells: Optional[List[NotebookNode]] = None) -> NotebookNo all_cells = cells else: # Default cells all_cells = [ - new_code_cell("a = 2", metadata={"tags": []}), - new_code_cell("b=22\nb", metadata={"tags": ["test"]}), + new_code_cell('a = 2', metadata={'tags': []}), + new_code_cell('b=22\nb', metadata={'tags': ['test']}), new_code_cell( - "", - metadata={"tags": ["dummy-outputs"]}, - outputs=[new_output("execute_result", data={"text/plain": "text"})], + '', + metadata={'tags': ['dummy-outputs']}, + outputs=[new_output('execute_result', data={'text/plain': 'text'})], ), ] diff --git a/testbook/tests/test_client.py b/testbook/tests/test_client.py index b019bb5..e57f4d5 100644 --- a/testbook/tests/test_client.py +++ b/testbook/tests/test_client.py @@ -9,20 +9,20 @@ ) -@pytest.fixture(scope="module") +@pytest.fixture(scope='module') def notebook(): - with testbook("testbook/tests/resources/inject.ipynb", execute=True) as tb: + with testbook('testbook/tests/resources/inject.ipynb', execute=True) as tb: yield tb -@pytest.mark.parametrize("cell_index_args, expected_result", [(2, 2), ("hello", 1)]) +@pytest.mark.parametrize('cell_index_args, expected_result', [(2, 2), ('hello', 1)]) def test_cell_index(cell_index_args, expected_result, notebook): assert notebook._cell_index(cell_index_args) == expected_result @pytest.mark.parametrize( - "cell_index_args, expected_error", - [([1, 2, 3], TypeError), ("non-existent-tag", TestbookCellTagNotFoundError)], + 'cell_index_args, expected_error', + [([1, 2, 3], TypeError), ('non-existent-tag', TestbookCellTagNotFoundError)], ) def test_cell_index_raises_error(cell_index_args, expected_error, notebook): with pytest.raises(expected_error): @@ -30,40 +30,40 @@ def test_cell_index_raises_error(cell_index_args, expected_error, notebook): @pytest.mark.parametrize( - "var_name, expected_result", + 'var_name, expected_result', [ - ("sample_dict", {"foo": "bar"}), - ("sample_list", ["foo", "bar"]), - ('sample_list + ["hello world"]', ["foo", "bar", "hello world"]), - ("sample_int", 42), - ("sample_int * 2", 84), - ("sample_str", "hello world"), - ('sample_str + " foo"', "hello world foo"), + ('sample_dict', {'foo': 'bar'}), + ('sample_list', ['foo', 'bar']), + ('sample_list + ["hello world"]', ['foo', 'bar', 'hello world']), + ('sample_int', 42), + ('sample_int * 2', 84), + ('sample_str', 'hello world'), + ('sample_str + " foo"', 'hello world foo'), ], ) def test_value(var_name, expected_result, notebook): assert notebook.value(var_name) == expected_result -@pytest.mark.parametrize("code", [("sample_int *= 2"), ("print(sample_int)"), ("")]) +@pytest.mark.parametrize('code', [('sample_int *= 2'), ('print(sample_int)'), ('')]) def test_value_raises_error(code, notebook): with pytest.raises(TestbookExecuteResultNotFoundError): notebook.value(code) @pytest.mark.parametrize( - "cell, expected_result", + 'cell, expected_result', [ ( { - "cell_type": "code", - "execution_count": 9, - "metadata": {}, - "outputs": [ + 'cell_type': 'code', + 'execution_count': 9, + 'metadata': {}, + 'outputs': [ { - "name": "stdout", - "output_type": "stream", - "text": "hello world\n" "foo\n" "bar\n", + 'name': 'stdout', + 'output_type': 'stream', + 'text': 'hello world\n' 'foo\n' 'bar\n', } ], }, @@ -74,8 +74,8 @@ def test_value_raises_error(code, notebook): """, ), ( - {"cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": []}, - "", + {'cell_type': 'code', 'execution_count': 9, 'metadata': {}, 'outputs': []}, + '', ), ], ) @@ -84,7 +84,7 @@ def test_output_text(cell, expected_result): @pytest.mark.parametrize( - "cell", [{}, {"cell_type": "markdown", "metadata": {}, "source": ["# Hello"]}] + 'cell', [{}, {'cell_type': 'markdown', 'metadata': {}, 'source': ['# Hello']}] ) def test_output_text_raises_error(cell): with pytest.raises(ValueError): @@ -93,16 +93,16 @@ def test_output_text_raises_error(cell): def test_cell_execute_result_index(notebook_factory): nb = notebook_factory() - with testbook(nb, execute="test") as tb: - assert tb.cell_execute_result(1) == [{"text/plain": "22"}] - assert tb.cell_execute_result(2) == [{"text/plain": "text"}] + with testbook(nb, execute='test') as tb: + assert tb.cell_execute_result(1) == [{'text/plain': '22'}] + assert tb.cell_execute_result(2) == [{'text/plain': 'text'}] def test_cell_execute_result_tag(notebook_factory): nb = notebook_factory() - with testbook(nb, execute="test") as tb: - assert tb.cell_execute_result("test") == [{"text/plain": "22"}] - assert tb.cell_execute_result("dummy-outputs") == [{"text/plain": "text"}] + with testbook(nb, execute='test') as tb: + assert tb.cell_execute_result('test') == [{'text/plain': '22'}] + assert tb.cell_execute_result('dummy-outputs') == [{'text/plain': 'text'}] def test_cell_execute_result_indexerror(notebook_factory): @@ -116,4 +116,4 @@ def test_cell_execute_result_tagnotfound(notebook_factory): nb = notebook_factory([]) with testbook(nb) as tb: with pytest.raises(TestbookCellTagNotFoundError): - tb.cell_execute_result("test") + tb.cell_execute_result('test') diff --git a/testbook/tests/test_datamodel.py b/testbook/tests/test_datamodel.py index 4330fb9..3892f16 100644 --- a/testbook/tests/test_datamodel.py +++ b/testbook/tests/test_datamodel.py @@ -3,20 +3,20 @@ from ..testbook import testbook -@pytest.fixture(scope="module") +@pytest.fixture(scope='module') def notebook(): - with testbook("testbook/tests/resources/datamodel.ipynb", execute=True) as tb: + with testbook('testbook/tests/resources/datamodel.ipynb', execute=True) as tb: yield tb def test_len(notebook): - mylist = notebook.ref("mylist") + mylist = notebook.ref('mylist') assert len(mylist) == 5 def test_iter(notebook): - mylist = notebook.ref("mylist") + mylist = notebook.ref('mylist') expected = [] for x in mylist: @@ -26,7 +26,7 @@ def test_iter(notebook): def test_getitem(notebook): - mylist = notebook.ref("mylist") + mylist = notebook.ref('mylist') mylist.append(6) assert mylist[-1] == 6 @@ -34,50 +34,50 @@ def test_getitem(notebook): def test_getitem_raisesIndexError(notebook): - mylist = notebook.ref("mylist") + mylist = notebook.ref('mylist') with pytest.raises(IndexError): mylist[100] def test_getitem_raisesTypeError(notebook): - mylist = notebook.ref("mylist") + mylist = notebook.ref('mylist') with pytest.raises(TypeError): - mylist["hello"] + mylist['hello'] def test_setitem(notebook): notebook.inject("mydict = {'key1': 'value1', 'key2': 'value1'}") - mydict = notebook.ref("mydict") + mydict = notebook.ref('mydict') - mydict["key3"] = "value3" - assert mydict["key3"] == "value3" + mydict['key3'] = 'value3' + assert mydict['key3'] == 'value3' - mylist = notebook.ref("mylist") + mylist = notebook.ref('mylist') mylist[2] = 10 assert mylist[2] == 10 def test_setitem_raisesIndexError(notebook): - mylist = notebook.ref("mylist") + mylist = notebook.ref('mylist') with pytest.raises(IndexError): mylist.__setitem__(10, 100) def test_setitem_raisesTypeError(notebook): - mylist = notebook.ref("mylist") + mylist = notebook.ref('mylist') with pytest.raises(TypeError): - mylist.__setitem__("key", 10) + mylist.__setitem__('key', 10) def test_contains(notebook): notebook.inject("mydict = {'key1': 'value1', 'key2': 'value1'}") - mydict = notebook.ref("mydict") + mydict = notebook.ref('mydict') - assert "key1" in mydict - assert "key2" in mydict - assert mydict.__contains__("key1") - assert mydict.__contains__("key2") + assert 'key1' in mydict + assert 'key2' in mydict + assert mydict.__contains__('key1') + assert mydict.__contains__('key2') diff --git a/testbook/tests/test_execute.py b/testbook/tests/test_execute.py index 94de706..db39864 100644 --- a/testbook/tests/test_execute.py +++ b/testbook/tests/test_execute.py @@ -4,18 +4,18 @@ from ..exceptions import TestbookRuntimeError, TestbookError -@pytest.fixture(scope="module") +@pytest.fixture(scope='module') def notebook(): - with testbook("testbook/tests/resources/foo.ipynb", execute=True) as tb: + with testbook('testbook/tests/resources/foo.ipynb', execute=True) as tb: yield tb def test_execute_cell(notebook): notebook.execute_cell(1) - assert notebook.cell_output_text(1) == "hello world\n[1, 2, 3]" + assert notebook.cell_output_text(1) == 'hello world\n[1, 2, 3]' notebook.execute_cell([2, 3]) - assert notebook.cell_output_text(3) == "foo" + assert notebook.cell_output_text(3) == 'foo' def test_execute_and_show_pandas_output(notebook): @@ -29,68 +29,68 @@ def test_execute_and_show_pandas_output(notebook): def test_execute_cell_tags(notebook): - notebook.execute_cell("test1") - assert notebook.cell_output_text("test1") == "hello world\n[1, 2, 3]" + notebook.execute_cell('test1') + assert notebook.cell_output_text('test1') == 'hello world\n[1, 2, 3]' - notebook.execute_cell(["prepare_foo", "execute_foo"]) - assert notebook.cell_output_text("execute_foo") == "foo" + notebook.execute_cell(['prepare_foo', 'execute_foo']) + assert notebook.cell_output_text('execute_foo') == 'foo' def test_execute_cell_raises_error(notebook): with pytest.raises(TestbookRuntimeError): try: - notebook.inject("1/0", pop=True) + notebook.inject('1/0', pop=True) except TestbookRuntimeError as e: assert e.eclass is ZeroDivisionError raise def test_testbook_with_execute(notebook): - notebook.execute_cell("execute_foo") - assert notebook.cell_output_text("execute_foo") == "foo" + notebook.execute_cell('execute_foo') + assert notebook.cell_output_text('execute_foo') == 'foo' def test_testbook_with_execute_context_manager(notebook): - notebook.execute_cell("execute_foo") - assert notebook.cell_output_text("execute_foo") == "foo" + notebook.execute_cell('execute_foo') + assert notebook.cell_output_text('execute_foo') == 'foo' def test_testbook_range(): - with testbook("testbook/tests/resources/inject.ipynb") as tb: + with testbook('testbook/tests/resources/inject.ipynb') as tb: tb.execute_cell(range(4)) assert tb.code_cells_executed == 4 - with testbook("testbook/tests/resources/inject.ipynb", execute=range(4)) as tb: + with testbook('testbook/tests/resources/inject.ipynb', execute=range(4)) as tb: assert tb.code_cells_executed == 4 @pytest.mark.parametrize( - "slice_params, expected_result", [(("hello", "str"), 6), ((2, 5), 4)] + 'slice_params, expected_result', [(('hello', 'str'), 6), ((2, 5), 4)] ) def test_testbook_slice(slice_params, expected_result): - with testbook("testbook/tests/resources/inject.ipynb") as tb: + with testbook('testbook/tests/resources/inject.ipynb') as tb: tb.execute_cell(slice(*slice_params)) assert tb.code_cells_executed == expected_result with testbook( - "testbook/tests/resources/inject.ipynb", execute=slice(*slice_params) + 'testbook/tests/resources/inject.ipynb', execute=slice(*slice_params) ) as tb: assert tb.code_cells_executed == expected_result def test_testbook_slice_raises_error(): with pytest.raises(TestbookError): - with testbook("testbook/tests/resources/inject.ipynb", execute=slice(3, 1, -1)): + with testbook('testbook/tests/resources/inject.ipynb', execute=slice(3, 1, -1)): pass -@testbook("testbook/tests/resources/exception.ipynb", execute=True) +@testbook('testbook/tests/resources/exception.ipynb', execute=True) def test_raise_exception(tb): with pytest.raises(TestbookRuntimeError): - tb.ref("raise_my_exception")() + tb.ref('raise_my_exception')() -@testbook("testbook/tests/resources/inject.ipynb") +@testbook('testbook/tests/resources/inject.ipynb') def test_underscore(tb): tb.inject( """ @@ -104,6 +104,6 @@ def foo(x): tb.execute() - foo = tb.ref("foo") + foo = tb.ref('foo') assert foo(2) == 3 diff --git a/testbook/tests/test_inject.py b/testbook/tests/test_inject.py index 2228e94..44e43b1 100644 --- a/testbook/tests/test_inject.py +++ b/testbook/tests/test_inject.py @@ -3,9 +3,9 @@ from ..testbook import testbook -@pytest.fixture(scope="module") +@pytest.fixture(scope='module') def notebook(): - with testbook("testbook/tests/resources/inject.ipynb", execute=True) as tb: + with testbook('testbook/tests/resources/inject.ipynb', execute=True) as tb: yield tb @@ -14,17 +14,17 @@ def inject_helper(*args, **kwargs): @pytest.mark.parametrize( - "args, kwargs", + 'args, kwargs', [ (None, None), ([1, 2], None), ((1, 2), None), ((True, False), None), - (["a", "b"], None), - ([1.1, float("nan"), float("inf"), float("-inf")], None), - ([{"key1": "value1"}, {"key2": "value2"}], None), - ((1, 2, False), {"key2": "value2"}), - ((None, None, False), {"key2": "value2"}), + (['a', 'b'], None), + ([1.1, float('nan'), float('inf'), float('-inf')], None), + ([{'key1': 'value1'}, {'key2': 'value2'}], None), + ((1, 2, False), {'key2': 'value2'}), + ((None, None, False), {'key2': 'value2'}), ], ) def test_inject(args, kwargs, notebook): @@ -32,7 +32,7 @@ def test_inject(args, kwargs, notebook): @pytest.mark.parametrize( - "code_block, expected_text", + 'code_block, expected_text', [ ( """ @@ -40,7 +40,7 @@ def foo(): print('I ran in the code block') foo() """, - "I ran in the code block", + 'I ran in the code block', ), ( """ @@ -48,7 +48,7 @@ def foo(arg): print(f'You passed {arg}') foo('bar') """, - "You passed bar", + 'You passed bar', ), ], ) @@ -57,7 +57,7 @@ def test_inject_code_block(code_block, expected_text, notebook): def test_inject_raises_exception(notebook): - values = [3, {"key": "value"}, ["a", "b", "c"], (1, 2, 3), {1, 2, 3}] + values = [3, {'key': 'value'}, ['a', 'b', 'c'], (1, 2, 3), {1, 2, 3}] for value in values: with pytest.raises(TypeError): @@ -65,16 +65,16 @@ def test_inject_raises_exception(notebook): def test_inject_before_after(notebook): - notebook.inject("say_hello()", run=False, after="hello") - assert notebook.cells[notebook._cell_index("hello") + 1].source == "say_hello()" + notebook.inject('say_hello()', run=False, after='hello') + assert notebook.cells[notebook._cell_index('hello') + 1].source == 'say_hello()' - notebook.inject("say_bye()", before="hello") - assert notebook.cells[notebook._cell_index("hello") - 1].source == "say_bye()" + notebook.inject('say_bye()', before='hello') + assert notebook.cells[notebook._cell_index('hello') - 1].source == 'say_bye()' with pytest.raises(ValueError): - notebook.inject("say_hello()", before="hello", after="bye") + notebook.inject('say_hello()', before='hello', after='bye') def test_inject_pop(notebook): - assert notebook.inject("1+1", pop=True).execute_result == [{"text/plain": "2"}] - assert notebook.cells[-1].source != "1+1" + assert notebook.inject('1+1', pop=True).execute_result == [{'text/plain': '2'}] + assert notebook.cells[-1].source != '1+1' diff --git a/testbook/tests/test_patch.py b/testbook/tests/test_patch.py index ea69fe0..ba5e122 100644 --- a/testbook/tests/test_patch.py +++ b/testbook/tests/test_patch.py @@ -4,15 +4,15 @@ import pytest -@pytest.fixture(scope="module") +@pytest.fixture(scope='module') def tb(): - with testbook("testbook/tests/resources/patch.ipynb", execute=True) as tb: + with testbook('testbook/tests/resources/patch.ipynb', execute=True) as tb: yield tb class TestPatch: @pytest.mark.parametrize( - "target, func", [("os.listdir", "listdir"), ("os.popen", "get_branch")] + 'target, func', [('os.listdir', 'listdir'), ('os.popen', 'get_branch')] ) def test_patch_basic(self, target, func, tb): with tb.patch(target) as mock_obj: @@ -20,22 +20,22 @@ def test_patch_basic(self, target, func, tb): mock_obj.assert_called_once() @pytest.mark.parametrize( - "target, func", [("os.listdir", "listdir"), ("os.popen", "get_branch")] + 'target, func', [('os.listdir', 'listdir'), ('os.popen', 'get_branch')] ) def test_patch_raises_error(self, target, func, tb): with pytest.raises(TestbookRuntimeError), tb.patch(target) as mock_obj: mock_obj.assert_called_once() def test_patch_return_value(self, tb): - with tb.patch("os.listdir", return_value=["file1", "file2"]) as mock_listdir: - assert tb.ref("listdir")() == ["file1", "file2"] + with tb.patch('os.listdir', return_value=['file1', 'file2']) as mock_listdir: + assert tb.ref('listdir')() == ['file1', 'file2'] mock_listdir.assert_called_once() class TestPatchDict: @pytest.mark.parametrize( - "in_dict, values", - [("os.environ", {"PATH": "/usr/bin"})], + 'in_dict, values', + [('os.environ', {'PATH': '/usr/bin'})], ) def test_patch_dict(self, in_dict, values, tb): with tb.patch_dict(in_dict, values, clear=True): diff --git a/testbook/tests/test_reference.py b/testbook/tests/test_reference.py index c9d476c..6fac580 100644 --- a/testbook/tests/test_reference.py +++ b/testbook/tests/test_reference.py @@ -4,57 +4,57 @@ from ..exceptions import TestbookAttributeError, TestbookSerializeError -@pytest.fixture(scope="module") +@pytest.fixture(scope='module') def notebook(): - with testbook("testbook/tests/resources/reference.ipynb", execute=True) as tb: + with testbook('testbook/tests/resources/reference.ipynb', execute=True) as tb: yield tb def test_create_reference(notebook): - a = notebook.ref("a") - assert repr(a) == "[1, 2, 3]" + a = notebook.ref('a') + assert repr(a) == '[1, 2, 3]' def test_create_reference_getitem(notebook): - a = notebook["a"] - assert repr(a) == "[1, 2, 3]" + a = notebook['a'] + assert repr(a) == '[1, 2, 3]' def test_create_reference_get(notebook): - a = notebook.get("a") - assert repr(a) == "[1, 2, 3]" + a = notebook.get('a') + assert repr(a) == '[1, 2, 3]' def test_eq_in_notebook(notebook): - a = notebook.ref("a") + a = notebook.ref('a') a.append(4) assert a == [1, 2, 3, 4] def test_eq_in_notebook_ref(notebook): - a, b = notebook.ref("a"), notebook.ref("b") + a, b = notebook.ref('a'), notebook.ref('b') assert a == b def test_function_call(notebook): - double = notebook.ref("double") + double = notebook.ref('double') assert double([1, 2, 3]) == [2, 4, 6] def test_function_call_with_ref_object(notebook): - double, a = notebook.ref("double"), notebook.ref("a") + double, a = notebook.ref('double'), notebook.ref('a') assert double(a) == [2, 4, 6] def test_reference(notebook): - Foo = notebook.ref("Foo") + Foo = notebook.ref('Foo') # Check that when a non-serializeable object is returned, it returns # a reference to that object instead - f = Foo("bar") + f = Foo('bar') - assert repr(f) == "\"\"" + assert repr(f) == '""' # Valid attribute access assert f.say_hello() @@ -63,7 +63,7 @@ def test_reference(notebook): with pytest.raises(TestbookAttributeError): f.does_not_exist - assert f.say_hello() == "Hello bar!" + assert f.say_hello() == 'Hello bar!' # non JSON-serializeable output with pytest.raises(TestbookSerializeError): diff --git a/testbook/tests/test_testbook.py b/testbook/tests/test_testbook.py index 84a9342..986d5f4 100644 --- a/testbook/tests/test_testbook.py +++ b/testbook/tests/test_testbook.py @@ -5,35 +5,35 @@ from ..testbook import testbook -@testbook("testbook/tests/resources/inject.ipynb", execute=True) +@testbook('testbook/tests/resources/inject.ipynb', execute=True) def test_testbook_execute_all_cells(tb): for cell in tb.cells[:-1]: assert cell.execution_count -@testbook("testbook/tests/resources/inject.ipynb", execute="hello") +@testbook('testbook/tests/resources/inject.ipynb', execute='hello') def test_testbook_class_decorator(tb): - assert tb.inject("say_hello()") + assert tb.inject('say_hello()') -@testbook("testbook/tests/resources/inject.ipynb") +@testbook('testbook/tests/resources/inject.ipynb') def test_testbook_class_decorator_execute_none(tb): assert tb.code_cells_executed == 0 -@testbook("testbook/tests/resources/inject.ipynb", execute=True) +@testbook('testbook/tests/resources/inject.ipynb', execute=True) def test_testbook_decorator_with_fixture(nb, tmp_path): assert True # Check that the decorator accept to be passed along side a fixture -@testbook("testbook/tests/resources/inject.ipynb", execute=True) -@pytest.mark.parametrize("cell_index_args, expected_result", [(2, 2), ("hello", 1)]) +@testbook('testbook/tests/resources/inject.ipynb', execute=True) +@pytest.mark.parametrize('cell_index_args, expected_result', [(2, 2), ('hello', 1)]) def test_testbook_decorator_with_markers(nb, cell_index_args, expected_result): assert nb._cell_index(cell_index_args) == expected_result -@pytest.mark.parametrize("cell_index_args, expected_result", [(2, 2), ("hello", 1)]) -@testbook("testbook/tests/resources/inject.ipynb", execute=True) +@pytest.mark.parametrize('cell_index_args, expected_result', [(2, 2), ('hello', 1)]) +@testbook('testbook/tests/resources/inject.ipynb', execute=True) def test_testbook_decorator_with_markers_order_does_not_matter( nb, cell_index_args, expected_result ): @@ -41,23 +41,23 @@ def test_testbook_decorator_with_markers_order_does_not_matter( def test_testbook_execute_all_cells_context_manager(): - with testbook("testbook/tests/resources/inject.ipynb", execute=True) as tb: + with testbook('testbook/tests/resources/inject.ipynb', execute=True) as tb: for cell in tb.cells[:-1]: assert cell.execution_count def test_testbook_class_decorator_context_manager(): - with testbook("testbook/tests/resources/inject.ipynb", execute="hello") as tb: - assert tb.inject("say_hello()") + with testbook('testbook/tests/resources/inject.ipynb', execute='hello') as tb: + assert tb.inject('say_hello()') def test_testbook_class_decorator_execute_none_context_manager(): - with testbook("testbook/tests/resources/inject.ipynb") as tb: + with testbook('testbook/tests/resources/inject.ipynb') as tb: assert tb.code_cells_executed == 0 def test_testbook_with_file_object(): - f = open("testbook/tests/resources/inject.ipynb") + f = open('testbook/tests/resources/inject.ipynb') with testbook(f) as tb: assert tb.code_cells_executed == 0 @@ -66,15 +66,15 @@ def test_testbook_with_file_object(): def test_testbook_with_notebook_node(): - nb = nbformat.read("testbook/tests/resources/inject.ipynb", as_version=4) + nb = nbformat.read('testbook/tests/resources/inject.ipynb', as_version=4) with testbook(nb) as tb: assert tb.code_cells_executed == 0 def test_function_with_testbook_decorator_returns_value(): - @testbook("testbook/tests/resources/inject.ipynb") + @testbook('testbook/tests/resources/inject.ipynb') def test_function(tb): - return "This should be returned" + return 'This should be returned' - assert test_function() == "This should be returned" + assert test_function() == 'This should be returned' diff --git a/testbook/tests/test_translators.py b/testbook/tests/test_translators.py index 6708412..802e53e 100644 --- a/testbook/tests/test_translators.py +++ b/testbook/tests/test_translators.py @@ -14,30 +14,30 @@ def __repr__(self): @pytest.mark.parametrize( - "test_input,expected", + 'test_input,expected', [ - ("foo", '"foo"'), + ('foo', '"foo"'), ('{"foo": "bar"}', '"{\\"foo\\": \\"bar\\"}"'), - ({"foo": "bar"}, '{"foo": "bar"}'), - ({"foo": '"bar"'}, '{"foo": "\\"bar\\""}'), - ({"foo": ["bar"]}, '{"foo": ["bar"]}'), - ({"foo": {"bar": "baz"}}, '{"foo": {"bar": "baz"}}'), - ({"foo": {"bar": '"baz"'}}, '{"foo": {"bar": "\\"baz\\""}}'), - (["foo"], '["foo"]'), - (["foo", '"bar"'], '["foo", "\\"bar\\""]'), - ([{"foo": "bar"}], '[{"foo": "bar"}]'), - ([{"foo": '"bar"'}], '[{"foo": "\\"bar\\""}]'), - (12345, "12345"), - (-54321, "-54321"), - (1.2345, "1.2345"), - (-5432.1, "-5432.1"), - (float("nan"), "float('nan')"), - (float("-inf"), "float('-inf')"), - (float("inf"), "float('inf')"), - (True, "True"), - (False, "False"), - (None, "None"), - (Foo("bar"), '''""'''), + ({'foo': 'bar'}, '{"foo": "bar"}'), + ({'foo': '"bar"'}, '{"foo": "\\"bar\\""}'), + ({'foo': ['bar']}, '{"foo": ["bar"]}'), + ({'foo': {'bar': 'baz'}}, '{"foo": {"bar": "baz"}}'), + ({'foo': {'bar': '"baz"'}}, '{"foo": {"bar": "\\"baz\\""}}'), + (['foo'], '["foo"]'), + (['foo', '"bar"'], '["foo", "\\"bar\\""]'), + ([{'foo': 'bar'}], '[{"foo": "bar"}]'), + ([{'foo': '"bar"'}], '[{"foo": "\\"bar\\""}]'), + (12345, '12345'), + (-54321, '-54321'), + (1.2345, '1.2345'), + (-5432.1, '-5432.1'), + (float('nan'), "float('nan')"), + (float('-inf'), "float('-inf')"), + (float('inf'), "float('inf')"), + (True, 'True'), + (False, 'False'), + (None, 'None'), + (Foo('bar'), '''""'''), ], ) def test_translate_type_python(test_input, expected): @@ -45,11 +45,11 @@ def test_translate_type_python(test_input, expected): @pytest.mark.parametrize( - "test_input,expected", [(3.14, "3.14"), (False, "false"), (True, "true")] + 'test_input,expected', [(3.14, '3.14'), (False, 'false'), (True, 'true')] ) def test_translate_float(test_input, expected): assert translators.Translator.translate(test_input) == expected def test_translate_assign(): - assert translators.Translator.assign("var1", [1, 2, 3]) == "var1 = [1, 2, 3]" + assert translators.Translator.assign('var1', [1, 2, 3]) == 'var1 = [1, 2, 3]' diff --git a/testbook/translators.py b/testbook/translators.py index 7d926da..3278665 100644 --- a/testbook/translators.py +++ b/testbook/translators.py @@ -8,16 +8,16 @@ class Translator(object): @classmethod def translate_raw_str(cls, val): """Reusable by most interpreters""" - return "{}".format(val) + return '{}'.format(val) @classmethod def translate_escaped_str(cls, str_val): """Reusable by most interpreters""" if isinstance(str_val, str): - str_val = str_val.encode("unicode_escape") + str_val = str_val.encode('unicode_escape') if sys.version_info >= (3, 0): - str_val = str_val.decode("utf-8") - str_val = str_val.replace('"', r"\"") + str_val = str_val.decode('utf-8') + str_val = str_val.replace('"', r'\"') return '"{}"'.format(str_val) @classmethod @@ -43,18 +43,18 @@ def translate_float(cls, val): @classmethod def translate_bool(cls, val): """Default behavior for translation""" - return "true" if val else "false" + return 'true' if val else 'false' @classmethod def translate_dict(cls, val): raise NotImplementedError( - "dict type translation not implemented for {}".format(cls) + 'dict type translation not implemented for {}'.format(cls) ) @classmethod def translate_list(cls, val): raise NotImplementedError( - "list type translation not implemented for {}".format(cls) + 'list type translation not implemented for {}'.format(cls) ) @classmethod @@ -77,7 +77,7 @@ def translate(cls, val): return cls.translate_list(val) elif isinstance(val, tuple): return cls.translate_tuple(val) - elif val.__class__.__name__ == "TestbookObjectReference": + elif val.__class__.__name__ == 'TestbookObjectReference': return val.name # Use this generic translation as a last resort @@ -86,12 +86,12 @@ def translate(cls, val): @classmethod def comment(cls, cmt_str): raise NotImplementedError( - "comment translation not implemented for {}".format(cls) + 'comment translation not implemented for {}'.format(cls) ) @classmethod def assign(cls, name, str_val): - return "{} = {}".format(name, str_val) + return '{} = {}'.format(name, str_val) class PythonTranslator(Translator): @@ -112,20 +112,20 @@ def translate_bool(cls, val): @classmethod def translate_dict(cls, val): - escaped = ", ".join( + escaped = ', '.join( [ - "{}: {}".format(cls.translate_str(k), cls.translate(v)) + '{}: {}'.format(cls.translate_str(k), cls.translate(v)) for k, v in val.items() ] ) - return "{{{}}}".format(escaped) + return '{{{}}}'.format(escaped) @classmethod def translate_list(cls, val): - escaped = ", ".join([cls.translate(v) for v in val]) - return "[{}]".format(escaped) + escaped = ', '.join([cls.translate(v) for v in val]) + return '[{}]'.format(escaped) @classmethod def translate_tuple(cls, val): - escaped = ", ".join([cls.translate(v) for v in val]) + ", " - return "({})".format(escaped) + escaped = ', '.join([cls.translate(v) for v in val]) + ', ' + return '({})'.format(escaped) diff --git a/testbook/utils.py b/testbook/utils.py index ef66a84..297a383 100644 --- a/testbook/utils.py +++ b/testbook/utils.py @@ -15,7 +15,7 @@ def random_varname(length=10): -------- random variable name as string of given length """ - return "".join(random.choice(string.ascii_lowercase) for _ in range(length)) + return ''.join(random.choice(string.ascii_lowercase) for _ in range(length)) def all_subclasses(klass):