-
Notifications
You must be signed in to change notification settings - Fork 252
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 tests for copying. Setup project for pytest. #88
Conversation
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.
Great start on the tests! Check out the comments I left and let me know if you have any questions.
constants.py
Outdated
@@ -7,3 +7,5 @@ class Constants: | |||
URL='https://github.com/alichtman/shallow-backup' | |||
AUTHOR_EMAIL='aaronlichtman@gmail.com' | |||
CONFIG_PATH='.shallow-backup' | |||
INVALIDS = [".Trash", ".npm", ".cache", ".rvm"] |
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.
Let's make the name a bit more descriptive, but this is a good refactor.
INVALIDS = [".Trash", ".npm", ".cache", ".rvm"] | |
INVALID_DIRS = [".Trash", ".npm", ".cache", ".rvm"] |
shallow_backup.py
Outdated
@@ -121,7 +121,7 @@ def copy_dir(source_dir, backup_path): | |||
""" | |||
Copy dotfolder from $HOME. | |||
""" | |||
invalid = {".Trash", ".npm", ".cache", ".rvm"} | |||
invalid = set(Constants.INVALIDS) |
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.
invalid = set(Constants.INVALIDS) | |
invalid = set(Constants.INVALID_DIRS) |
tests/test_copies.py
Outdated
from shallow_backup import _copy_file, copy_dir | ||
from constants import Constants | ||
|
||
TEST_DIR = 'test-directory' |
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.
Let's rename these all to be shallow-backup-...
to decrease the chance of conflicting file/directory names and accidentally destroying someone's data.
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.
And shorten directory
to just dir
tests/test_copies.py
Outdated
Test that copying a directory works as expected | ||
""" | ||
dir_to_copy = '/test/' | ||
os.mkdir(TEST_DIR + dir_to_copy) |
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's better practice to use os.path.join()
for creating paths since that's cross-platform compatible. Let's do that here.
for directory in DIRS: | ||
try: | ||
os.mkdir(directory) | ||
except FileExistsError: |
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.
If the directories exist already, instead of removing them immediately (since the teardown methods should remove them, so if they exist, it's possible the directories weren't created by us), we should print an error message and ask the user whether they want to remove the files or exit, using the inquirer
library in the same style as the CLI.
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.
Although I'm open to talk about this one. With the file name change to be much less generic, the prompt may be overkill and could interfere with scripting. What do you think?
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.
Yeah I did this so that if it was ever run in a CI environment we shouldn't expect to have any issues. A prompt in a CI environment would hang the build.
We can try to be smarter about this and append the current datetime to definitely avoid conflicts and then remove all dirs with a suffix shallow-copy-dir-*
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.
TBH I think that might be a bit of over-engineering for a simple unit test solution. Going to keep as is for now but I'm happy to throw it is (simple change) if you deem necessary
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.
We can try to be smarter about this and append the current datetime to definitely avoid conflicts and then remove all dirs with a suffix
shallow-copy-dir-*
This is a great solution -- let's do it.
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.
After further consideration, let's do shallow-backup-test-dir
with no date after it because it's unlikely that someone has a pre-existing dir named that which isn't used by shallow-backup
.
Pipfile
Outdated
@@ -8,6 +8,7 @@ click = "*" | |||
inquirer = "*" | |||
gitpython = "*" | |||
colorama = "*" | |||
pytest = "*" |
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.
Shouldn't there be a Pipfile.lock update, as well? Can you commit that?
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.
I took care of the Pipfile changes in my previous PR, so this is on master already. You should remove the Pipfile
and Pipfile.lock
files from your commit (if they differ from the ones I committed. If they're the same, git will just take care of it.)
@alichtman I addressed all comments besides the ones I explained. Let me know if you still have concerns on those choices. |
Two minor changes and we can get this merged in, @pyasi |
tests/test_copies.py
Outdated
from shallow_backup import _copy_file, _copy_dir | ||
from constants import Constants | ||
|
||
TEST_DIR = 'shallow-backup-test-dir' |
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.
Let's name one of these TEST_DIR_FOR_BACKUP
and one of them TEST_DIR_TO_BACKUP
so there's no confusion about which is which.
For future test improvements.
In reading through these tests again, there are some definite improvements that could be made. I've added TODOs for these in the code, but I wanted to get the structure merged in so other people to work on it, as well. I've opened a bunch of other testing issues, if you're interested in taking a look at those. I think it's really important to have a comprehensive testing suite for this, and I'll work on building it out over time, but the help right now is definitely appreciated. Again, thanks for the contribution. I'd be excited to work on some more features with you in the future. |
One of your test changes broke a test. Let's get in the habit of running the suite before commiting/merging. I'll take a look at some of the other testable pieces. |
You're totally correct. I did a quick refactor in the GitHub editor without actually pulling it to test. That was sloppy... Is the error on line 42? |
This is just a start to the testing journey possibilities! But wanted to get my feet wet in the repository.