Exemplo n.º 1
0
def open_sources(args):
    sources = [
        Source(TodoTxt(pathlib.Path(fn).expanduser().resolve()))
        for fn in args.filename
    ]
    for source in sources:
        if source.filename.exists():
            source.parse()
    return sources
Exemplo n.º 2
0
def prepare(todotxt, config):
    cfg = get_config(config)

    if len(todotxt) == 0:
        todotxt = cfg.get('General', 'todotxt-file')
    if len(todotxt) == 0:
        raise ValueError(f'No todotxt file given nor configured in {config}')

    todo = TodoTxt(todotxt)
    todo.parse()

    if cfg.getboolean('General', 'usetex'):
        plt.rc('text', usetex=True)

    style = cfg.get('General', 'matplotlib-style')
    if len(style) > 0:
        plt.style.use(style)

    return cfg, todo
Exemplo n.º 3
0
class TestStr(unittest.TestCase):
    """Reads a well formated todo.txt and checks if the internal string
    representation is the same as the respective line in the file."""
    def setUp(self):
        self.filename = 'tests/todo.wellformatted.txt'
        self.todo = TodoTxt(self.filename)

    def test_str(self):
        lines = []
        with open(self.filename, 'r') as f:
            for line in f.readlines():
                lines.append(line.strip())

        for entry in self.todo.entrys:
            self.assertTrue(self.todo._entry_to_string(entry) in lines)
Exemplo n.º 4
0
class Test(unittest.TestCase):
    def setUp(self):
        self.filename = 'tests/todo.test.txt'
        self.todo = TodoTxt(self.filename)

    def test_num_entries(self):
        self.assertEquals(9, len(self.todo.entrys))

    def test_get_filterd(self):
        one_keyword = self.todo.get(keywords=['Handy'])
        self.assertEquals(2, len(one_keyword))

        two_projects = self.todo.get(projects=['aa', 'server'])
        self.assertEquals(1, len(two_projects))

    def test_add(self):
        self.todo.add(text='A test @dev')
        self.assertEquals(10, len(self.todo.entrys))

    def test_write(self):
        """Adds one entry and writes all entrys to a new file. Then checks if
        all entrys have been correctly written to the file."""

        new_filename = 'tests/todo.write.txt'
        self.todo.add(text='A test @dev')
        self.assertEquals(10, len(self.todo.entrys))

        # Write to another file
        self.todo.write(new_filename)

        lines = []
        with open(new_filename, 'r') as f:
            for line in f.readlines():
                lines.append(line.strip())

        for entry in self.todo.entrys:
            string = self.todo._entry_to_string(entry)
            self.assertTrue(
                string in lines,
                '[{0}] has not been written to file'.format(string))
Exemplo n.º 5
0
class TestStr(unittest.TestCase):
    """Reads a well formated todo.txt and checks if the internal string
    representation is the same as the respective line in the file."""

    def setUp(self):
        self.filename = "tests/todo.wellformatted.txt"
        self.todo = TodoTxt(self.filename)

    def test_str(self):
        lines = []
        with open(self.filename, "r") as f:
            for line in f.readlines():
                lines.append(line.strip())

        for entry in self.todo.entrys:
            self.assertTrue(self.todo._entry_to_string(entry) in lines)
Exemplo n.º 6
0
class Test(unittest.TestCase):
    def setUp(self):
        self.filename = "tests/todo.test.txt"
        self.todo = TodoTxt(self.filename)

    def test_num_entries(self):
        self.assertEquals(9, len(self.todo.entrys))

    def test_get_filterd(self):
        one_keyword = self.todo.get(keywords=["Handy"])
        self.assertEquals(2, len(one_keyword))

        two_projects = self.todo.get(projects=["aa", "server"])
        self.assertEquals(1, len(two_projects))

    def test_add(self):
        self.todo.add(text="A test @dev")
        self.assertEquals(10, len(self.todo.entrys))

    def test_write(self):
        """Adds one entry and writes all entrys to a new file. Then checks if
        all entrys have been correctly written to the file."""

        new_filename = "tests/todo.write.txt"
        self.todo.add(text="A test @dev")
        self.assertEquals(10, len(self.todo.entrys))

        # Write to another file
        self.todo.write(new_filename)

        lines = []
        with open(new_filename, "r") as f:
            for line in f.readlines():
                lines.append(line.strip())

        for entry in self.todo.entrys:
            string = self.todo._entry_to_string(entry)
            self.assertTrue(string in lines, "[{0}] has not been written to file".format(string))
Exemplo n.º 7
0
 def setUp(self):
     self.filename = 'tests/todo.test.txt'
     self.todo = TodoTxt(self.filename)
Exemplo n.º 8
0
 def test_no_file(self):
     with self.assertRaises(IOError):
         TodoTxt('filenotfound.txt')
Exemplo n.º 9
0
 def setUp(self):
     self.filename = 'tests/todo.wellformatted.txt'
     self.todo = TodoTxt(self.filename)
Exemplo n.º 10
0
 def setUp(self):
     self.filename = "tests/todo.test.txt"
     self.todo = TodoTxt(self.filename)
Exemplo n.º 11
0
 def setUp(self):
     self.filename = "tests/todo.wellformatted.txt"
     self.todo = TodoTxt(self.filename)