def test_unsupported_os():
    with patch('subprocess.check_call', MagicMock(return_value="NOOP")):

        with patch('platform.system', MagicMock(return_value="NotDarwinWindowsLinux")):
            with pytest.raises(Exception) as excinfo:
                open_folder("/")
            assert str(excinfo.value).startswith('Your operating system was not recognized.')
def test_supported_os():
    with patch('subprocess.check_call', MagicMock(return_value="NOOP")):

        with patch('platform.system', MagicMock(return_value="Linux")):
            result = open_folder("/")
            assert result == None
        with patch('platform.system', MagicMock(return_value="Darwin")):
            result = open_folder("/")
            assert result == None
        with patch('platform.system', MagicMock(return_value="Windows")):
            result = open_folder("/")
            assert result == None
def test_folder_exists():
    with patch('subprocess.check_call', MagicMock(return_value="NOOP")):
        result = open_folder(".")
        assert result == None
def test_folder_does_not_exists():
    with patch('subprocess.check_call', MagicMock(return_value="NOOP")):
        with pytest.raises(Exception) as excinfo:
            open_folder("it_is_very_unlikely_that_this_file_exists_20150718")
        assert str(excinfo.value) == ('Folder does not exist.')
Esempio n. 5
0



the_today_folder = config.get("global","the_today_folder")

# Get rid of the old symlink first
try:
    os.remove(the_today_folder)
except:
    print("Warning: Unabled to remove old symlink.")

# Create a symlink to make it easy for user to open up "today"
# (NOTE TO SELF: Perhaps windows users just don't get this convenience?
#   (because no symlinks on windows)
cmd = 'ln -s "%s" "%s"' % (todays_folder,the_today_folder)
try:
    os.system(cmd)
except:
    print "Failed to create a symlink for today.   This is probably OK."


file_count = len( [name for name in os.listdir(todays_folder) ]   )

if (file_count == 0):
    msg = "Today's tickler file was not opened because it contained no files. \n\n%s" % datetime.datetime.fromtimestamp(time.time()).strftime('%Y-%m-%d %H:%M:%S')
    notify_user(msg)
else:
    # Go ahead and pop open the folder so it's front and center
    open_folder(todays_folder)