Skip to content
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

Bugfixes and refactoring #35

Merged
merged 9 commits into from
Apr 24, 2020

Conversation

bricoletc
Copy link
Collaborator

This PR closes #29 and #33 and refactors tests

Added

  • Bugfixes in formatting for the two issues mentioned above
  • While processing both, I (of course...) hit some other formatting bugs/issues. I have added them as 3 failing tests. We can add them as issues. They are:
    • Triple quoted strings can get overindented for eg in shell context
    • Python code preceding nested snakecode does not get blacked
    • Python code following nested snakecode gets blacked but is an issue

The last two are totally related and should go in same issue. The first one doesn't really have to be an issue, not sure.

Changed

  • I refactored tests relating to configuration (pyproject.toml, user-specified toml, black toml settings, config adherence) to a source file test_config.py. I find this much more modular and readable.
  • In the process of refactoring I found a bug due to use of os.chdir(tmpdir) when using tmpdir pytest fixture. Unrelated tests can then run from inside there and were trying to use created pyproject.toml. So I switched to using testdir fixture which uses tmpdir and starts the test in a tmpdir, but doesnt stay there. I added that plugin in conftest.py.
  • I subgrouped some tests under classes, for eg the CLI-related tests under CLIDiff, CLICheck, etc.. in test_snakefmt.

Unfortunately this means triple quoted strings get overindented for now
Could be dropped to the next parameter. With unit test.
* Config-related tests in their own source file
* More grouping of tests under classes to document what they are testing in common
In test_config. testdir uses tmpdir fixture tmp directory as cwd.
This avoids a bug in which subsequent unrelated tests were run in tmpdir
due to os.chdir.
They are due to python formatting either:
* Being triggered too early when exiting nested snakecode context
* Being not triggered when entering nested snakecode context
And a grammar test passing formatting with all possibly duplicated
keywords
* Config-related tests placed in test_config
* Regex based snakefmt tests placed together and class renamed for clarity
@bricoletc bricoletc requested review from mbhall88 and removed request for johanneskoester April 24, 2020 10:50
@codecov
Copy link

codecov bot commented Apr 24, 2020

Codecov Report

Merging #35 into dev will increase coverage by 0.48%.
The diff coverage is 96.87%.

Impacted file tree graph

@@            Coverage Diff             @@
##              dev      #35      +/-   ##
==========================================
+ Coverage   94.09%   94.57%   +0.48%     
==========================================
  Files          10        9       -1     
  Lines         711      738      +27     
  Branches      118      123       +5     
==========================================
+ Hits          669      698      +29     
+ Misses         31       29       -2     
  Partials       11       11              
Flag Coverage Δ
#unittests 94.57% <96.87%> (+0.48%) ⬆️
Impacted Files Coverage Δ
snakefmt/parser/syntax.py 96.53% <92.85%> (+1.16%) ⬆️
snakefmt/formatter.py 99.25% <100.00%> (+0.02%) ⬆️
snakefmt/parser/parser.py 90.00% <100.00%> (+0.20%) ⬆️
snakefmt/types.py 100.00% <100.00%> (ø)
snakefmt/__init__.py

@mbhall88
Copy link
Member

Ahh glad you found "Triple quoted strings can get over indented for eg in shell context". I was going to raise this. I think we should leave the (inside) of the shell command as is. i.e. only format that its start and end """ are consistent with shell:

}


def operator_skip_spacing(prev_token: Token, token: Token):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return type needed

@@ -181,22 +195,26 @@ def effective_indent(self) -> int:

def get_next_queriable(self, snakefile) -> Syntax.Status:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

snakefile type annotation

@@ -318,10 +344,12 @@ def flush_param(self, parameter: Parameter, skip_empty: bool = False) -> None:
if not parameter.has_value() and skip_empty:
return

if parameter.has_key(): # noqa: W601
if parameter.has_a_key(): # noqa: W601
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we can remove the flake8 ignore comment now?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, i changed the signature for that reason, will do!

@mbhall88
Copy link
Member

mbhall88 commented Apr 24, 2020

Good pickup on the os.chdir problem. This is probably the thing that has been causing me problems in the past with pytest on the CI. Thanks for the fix.

No longer indent triple quoted strings, they are left as is.
With unit tests.
@bricoletc
Copy link
Collaborator Author

Ahh glad you found "Triple quoted strings can get over indented for eg in shell context". I was going to raise this. I think we should leave the (inside) of the shell command as is. i.e. only format that its start and end """ are consistent with shell:

You're totally right. I think that only the first triple quote should conform to shell (or whatever keyword) and the rest should be left as the user gave it.

This inspired me and I implemented a fix, with two unit tests.

@bricoletc
Copy link
Collaborator Author

The changes I've added have not led to the failing CI, i think it is tied to os.stat in the failing test

@bricoletc bricoletc merged commit 84463e2 into snakemake:dev Apr 24, 2020
@bricoletc bricoletc deleted the bugfixes_and_refactoring branch April 26, 2020 14:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants