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

Include tests to the python program that can be executed by github workflow #7

Closed
funbeedev opened this issue Nov 20, 2020 · 10 comments · Fixed by #10
Closed

Include tests to the python program that can be executed by github workflow #7

funbeedev opened this issue Nov 20, 2020 · 10 comments · Fixed by #10
Assignees
Labels
help wanted Help is welcome / Extra attention is needed testing Involves testing and QA

Comments

@funbeedev
Copy link
Member

funbeedev commented Nov 20, 2020

Current Behaviour

Execution of the python program in the github workflow will fail.

Changes Requested

Include tests in the python program.
Setup workflow to execute these tests.

@funbeedev funbeedev added testing Involves testing and QA help wanted Help is welcome / Extra attention is needed labels Nov 20, 2020
@Stedders
Copy link
Contributor

I'll look at this, it will help with #5 as well, under https://github.com/Stedders/AutomateGitRepoSetup/tree/Stedders.

@funbeedev
Copy link
Member Author

Great, thanks. Please issue a PR per major change you are making.
Also I can see in your fork the code formatting is changed in some parts but please keep the original formats and only change parts of the code that you are adding functionality to.
Note, you can ignore any linting errors to do with line numbers too long.

@Stedders
Copy link
Contributor

Hey @funbeedev

I've gone through and reverted the changes to the main file, it is difficult to unit test the code but I have committed a change that shows how it could be done.

On the latest commit of my branch I have added a test folder with a pytest script, this excutes the main start_program_flow function, the git workflow is setup to run pytest on every push.

I would strongly recommend refactoring the code with the following changes...

  1. Allows the config_file path to be variable and passed into start_program_flow() - allows us to generate configurations separate to the root directory
  2. Don't read the configuration in the module scope - as it stands the config is loaded when the module is loaded from the running dir, this results in all variables being defined at start
  3. Add arguments to the functions so they are not all reading from a single object in the outer scope - allows for more specificof the functions

As it stands I won't create the PR as the code fails flake8 linting (start_program_flow() is not in the linting scope as it is checking the code statically), this can be rectified but would need the config.ini file in the route of the directory to be manipulated during running, which feels wrong.

@funbeedev
Copy link
Member Author

@Stedders Thanks, I'll review your changes and suggestions and get back to you soon.
Btw, you can still issue the PR if you want even though everything might not be working. It makes it easier for me to pull your changes.
Also you can make changes to a PR after its issued by just pushing more changes to your fork!

@Stedders Stedders mentioned this issue Nov 24, 2020
1 task
@funbeedev
Copy link
Member Author

funbeedev commented Nov 25, 2020

@Stedders
In response to your suggestions on refactoring:

  1. Allows the config_file path to be variable and passed into start_program_flow() - allows us to generate configurations separate to the root directory

Is this just for more flexibility? How do you suggest the path of the config file be passed in?

  1. Don't read the configuration in the module scope - as it stands the config is loaded when the module is loaded from the running dir, this results in all variables being defined at start

Do you just mean to load the config within a function instead?

  1. Add arguments to the functions so they are not all reading from a single object in the outer scope - allows for more specificof the functions

I assume this relates to your point 2 and is about avoid use of global variables. I agree this aspect of the code needs to be improved! I'll create an issue for this.

@Stedders
Copy link
Contributor

Is this just for more flexibility? How do you suggest the path of the config file be passed in?

I would recommend that we add a param start_program_flow(config_file)

  1. If you want the path to always be config.ini then the __main__section will call start_program_flow('config.ini') to set it
  2. Testing can call start_program_flow('test-1.ini'), start_program_flow('test-2.ini'), etc...
  3. In the future you could add it as an argument to the program that can be passed through

Do you just mean to load the config within a function instead?

Yes, there are a couple of options...

  1. Use a global that can be accessed by all functions
  2. Pass the config items to the functions separately

I would prefer the latter, as it allows for more granular testing - for example commit_files(msg, repo_directory) can be tested multiple times with different messages - normal, blank, None, Japanese characters, etc... very quickly and specifically

I assume this relates to your point 2 and is about avoid use of global variables. I agree this aspect of the code needs to be improved! I'll create an issue for this.

👍 it feels like the better way of doing it.

@funbeedev
Copy link
Member Author

@Stedders
Sorry the delay in responding.

Those are all great suggestions, thank you! I've made issues based on your suggestions and they will be addressed soon.

@Stedders
Copy link
Contributor

Stedders commented Dec 7, 2020

@funbeedev - I'm happy to hold on the unit testing, in addition I can pick up any other little bits you need help with (either coding or reviewing).

@funbeedev
Copy link
Member Author

@Stedders Thanks, your help is appreciated!
See PR #16. This removes use of globals. Could you review the changes?

@funbeedev
Copy link
Member Author

funbeedev commented Dec 13, 2020

@Stedders I've made your suggested changes now and it's merged into the repo. For the relevant changes see PR #16 and #17.
Do you want to pull these changes and update the test in your PR?
Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Help is welcome / Extra attention is needed testing Involves testing and QA
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants