-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
413 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,6 @@ | ||
*.pyc | ||
*.pyc | ||
.cache | ||
.tmontmp | ||
.testmondata | ||
macprefsc | ||
.coverage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,12 @@ | ||
{ | ||
"cSpell.words": [ | ||
"cSpell.words": [ | ||
"macprefs", | ||
"plist", | ||
"pytest", | ||
"symlinks" | ||
], | ||
], | ||
"python.unitTest.pyTestArgs": [ | ||
"." | ||
], | ||
"python.unitTest.pyTestEnabled": true | ||
} | ||
"python.unitTest.pyTestEnabled": false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
// See https://go.microsoft.com/fwlink/?LinkId=733558 | ||
// for the documentation about the tasks.json format | ||
"version": "2.0.0", | ||
"tasks": [ | ||
{ | ||
"label": "Run All Tests with watch", | ||
"type": "shell", | ||
"command": "ptw --onfail 'say failed' -- --testmon ", | ||
"isBackground": true, | ||
"presentation": { | ||
"echo":false, | ||
"reveal": "never" | ||
}, | ||
"problemMatcher": [] | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
clean: | ||
find . -name '*.pyc' -delete | ||
|
||
setup: | ||
pip install -r requirements.txt | ||
|
||
test: | ||
pytest --cov=. | ||
|
||
lint: | ||
pylint *.py | ||
|
||
publish: | ||
|
||
|
||
help: | ||
@echo "COMMANDS:" | ||
@echo " clean Remove all generated files." | ||
@echo " setup Setup development environment." | ||
@echo " test Run tests." | ||
@echo " lint Run analysis tools." | ||
@echo " publish Tag and push to github and update the brew formula with the new url and sha256 and push to github |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,18 @@ | ||
import os | ||
from os import path | ||
|
||
BACKUP_DIR = os.environ['MACPREFS_BACKUP_DIR'] if 'MACPREFS_BACKUP_DIR' in os.environ else path.join( | ||
path.expanduser("~"), "Dropbox", "MacPrefsBackup") | ||
|
||
def get_backup_dir(): | ||
backup_dir = "" | ||
if 'MACPREFS_BACKUP_DIR' in os.environ: | ||
backup_dir = os.environ['MACPREFS_BACKUP_DIR'] | ||
else: | ||
backup_dir = path.join(path.expanduser( | ||
"~"), "Dropbox", "MacPrefsBackup") | ||
if not os.path.exists(backup_dir): | ||
os.makedirs(backup_dir) | ||
return backup_dir | ||
|
||
|
||
def get_backup_file_path(domain): | ||
return path.join(get_backup_dir(), domain + ".plist") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# pytest.ini | ||
|
||
[pytest] | ||
addopts = --maxfail=2 -s --tb=native -v -m "not integration" | ||
markers = integration: integration tests | ||
|
||
[pytest-watch] | ||
nobeep = True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# Needed to run the tests | ||
# Run "pip install -r requirements.txt" then pytest | ||
mock | ||
pylint | ||
pytest | ||
pytest-cov | ||
pytest-testmon | ||
pytest-watch |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
from os import path | ||
from mock import patch | ||
|
||
import backup_preferences | ||
from config import get_backup_dir | ||
|
||
|
||
@patch("backup_preferences.execute_shell") | ||
def test_backup(execute_shell_mock): | ||
execute_shell_mock.side_effect = execute_shell_func | ||
backup_preferences.backup() | ||
|
||
|
||
def execute_shell_func(*args): | ||
command = args[0] | ||
if command[1] == "domains": | ||
return domains_func(command) | ||
if command[1] == "export": | ||
return exports_func(command) | ||
|
||
|
||
def domains_func(command): | ||
assert isinstance(command, list) | ||
assert len(command) == 2 | ||
assert command[0] == "defaults" | ||
assert command[1] == "domains" | ||
return ", ".join(["asdf.com"]) | ||
|
||
|
||
def exports_func(command): | ||
assert isinstance(command, list) | ||
assert len(command) == 4 | ||
assert command[0] == "defaults" | ||
assert command[1] == "export" | ||
assert "NSGlobalDomain" in command[2] or "asdf.com" in command[2] | ||
backup_dir = get_backup_dir() | ||
nsgd_file = path.join(backup_dir, "/NSGlobalDomain.plist") | ||
asdf_file = path.join(backup_dir, "asdf.com.plist") | ||
assert nsgd_file in command[3] or asdf_file in command[3] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import backup_system_preferences | ||
from mock import patch | ||
|
||
|
||
@patch("backup_system_preferences.execute_shell") | ||
def test_backup(execute_shell_mock): | ||
execute_shell_mock.side_effect = execute_shell_func | ||
backup_system_preferences.backup() | ||
|
||
|
||
def execute_shell_func(*args): | ||
arg_length = len(args) | ||
assert arg_length > 0 | ||
command = args[0] | ||
assert command[0] == "defaults" | ||
assert command[1] == "export" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import os | ||
from os import path | ||
import config | ||
|
||
|
||
def test_get_backup_dir(): | ||
backup_dir = config.get_backup_dir() | ||
assert backup_dir is not None | ||
|
||
def test_get_backup_dir_works_with_environ(): | ||
os.environ['MACPREFS_BACKUP_DIR'] = "asdf" | ||
backup_dir = config.get_backup_dir() | ||
assert "asdf" in backup_dir | ||
|
||
|
||
def test_get_backup_file_path(): | ||
assert config.get_backup_file_path("asdf.com") == path.join( | ||
config.get_backup_dir(), "asdf.com.plist") |
Oops, something went wrong.