Honestly it's been a while, not sure what I was doing

and don't care enough to find out
Adam Goldsmith 4 years ago
parent 4d27a34fa2
commit 7ded307b13
  1. 18
  2. 11

@ -16,7 +16,7 @@ def getSub(item):
if "/:" not in item:
return None
sub=re.findall("[^ ]+/:[.A-Za-z0-9_]+", item)[0]
sub = re.findall("[^ ]+/:[.A-Za-z0-9_]+", item)[0]
except IndexError:
return None
return sub.split("/:")
@ -24,7 +24,8 @@ def getSub(item):
def addSub(num, sub, edit=True):
with open(os.getenv("TODO_FILE"), "r") as todoFile:
lines = todoFile.readlines()
if getSub(lines[num-1]) is not None and getSub(lines[num-1])[0] != sub:
if getSub(lines[num-1]) is not None and getSub(lines[num-1])[0] == sub:
sys.exit("The item already has a sub \"" + sub + "\":" + "\n" + lines[num-1][:-1])
if not os.path.exists(os.path.join(os.getenv("TODO_DIR"), sub)):
os.mkdir(os.path.join(os.getenv("TODO_DIR"), sub))
@ -50,7 +51,7 @@ def showSub(item, indent=0, color=True):
sub = getSub(item)
if sub is None:
sys.exit("This item does not have a sub")
command = ["todo.sh", "listfile", os.path.join(sub[0], sub[1])]
command = ["todo.sh", "listfile", os.path.join(sub[0], sub[1])]
if not color:
command.insert(1, "-p")
p = subprocess.Popen(command, stdout=subprocess.PIPE)
@ -70,11 +71,18 @@ def showAll(out=sys.stdout, color=True):
out.write(showSub(line, indent=2, color=color))
def main(argv):
if len(argv) < 3:
if(argv[1] == "usage"):
print(" sub")
print(" list subs")
print(" sub add [itemNum] [sub]")
print(" add a sub [sub] to [itemNum]")
print(" sub edit [itemNum]")
print(" edit the sub in [itemNum]")
elif len(argv) < 3:
elif argv[2] == "add":
if len(argv) != 5:
sys.exit("Usage: " + argv[1] + " add [itemNum] [subName]")
sys.exit("Usage: " + argv[1] + " add [itemNum] [sub]")
itemNum = int(argv[3])
addSub(itemNum, argv[4])
elif argv[2] == "edit":

@ -58,19 +58,26 @@ class TestShowAll(unittest.TestCase):
class TestAdd(unittest.TestCase):
def setUp(self):
import shutil
shutil.rmtree(os.path.join(TEST_DATA_DIR, "test_add"))
if os.path.exists(os.path.join(TEST_DATA_DIR, "test_add")):
shutil.rmtree(os.path.join(TEST_DATA_DIR, "test_add"))
os.mkdir(os.path.join(TEST_DATA_DIR, "test_add"))
def test_add_sub(self):
with open(os.path.join(TEST_DATA_DIR, "test_add/todo.txt"), "w") as f:
f.write("(Z) gibberish")
sub.addSub(1, "sub", False)
out = sub.getSub(sub.getItem(1))
self.assertTrue(out is not None)
fileExists = os.path.isfile(os.path.join(os.getenv("TODO_DIR"), out[0], out[1]))
def test_add_existing_sub(self):
with open(os.path.join(TEST_DATA_DIR, "test_add/todo.txt"), "w") as f:
f.write("(Z) gibberish sub:/test1.txt\n")
with self.assertRaises(SystemExit):
sub.addSub(1, "sub", False)
class TestEdit(unittest.TestCase):
def test_edit(self):
from unittest.mock import MagicMock