Beispiel #1
0
    def setUp(self):
        self.blog_path = path.temppath('blog')
        self.site_path = path.temppath('site')
        os.makedirs(self.blog_path)

        with open(os.path.join(self.blog_path, 'foo.txt'), 'w') as f:
            f.write('Foo')
        with open(os.path.join(self.blog_path, 'bar.txt'), 'w') as f:
            f.write('Bar')
        with open(os.path.join(self.blog_path, '2018-01-01-foo.txt'),
                  'w') as f:
            f.write('Foo')
        with open(os.path.join(self.blog_path, '2018-01-02-bar.txt'),
                  'w') as f:
            f.write('Bar')
        with open(os.path.join(self.blog_path, 'header-foo.txt'), 'w') as f:
            f.write('<!-- tag: foo -->Foo')
        with open(os.path.join(self.blog_path, 'header-bar.txt'), 'w') as f:
            f.write('<!-- title: bar -->Bar')
        with open(os.path.join(self.blog_path, 'placeholder-foo.txt'),
                  'w') as f:
            f.write('<!-- title: foo -->{{ title }}:{{ author }}:Foo')
        with open(os.path.join(self.blog_path, 'placeholder-bar.txt'),
                  'w') as f:
            f.write(
                '<!-- title: bar --><!-- render: yes -->{{ title }}:{{ author }}:Bar'
            )
Beispiel #2
0
 def test_move_dir_cleanup(self):
     src = os.path.join(path.temppath(), 'foo')
     dst = os.path.join(path.temppath(), 'bar')
     os.makedirs(dst)
     path.move(src, dst)
     self.assertFalse(os.path.isdir(src))
     self.assertFalse(os.path.isdir(dst))
Beispiel #3
0
 def test_move_file_cleanup(self):
     src = os.path.join(path.temppath(), 'foo.txt')
     dst = os.path.join(path.temppath(), 'bar.txt')
     with open(dst, 'w') as f:
         f.write('foo')
     path.move(src, dst)
     self.assertFalse(os.path.isfile(src))
     self.assertFalse(os.path.isfile(dst))
 def test_fwrite_makedir(self):
     text = 'baz\nqux\n'
     dirpath = path.temppath('foo', 'bar')
     filepath = os.path.join(dirpath, 'foo.txt')
     makesite.fwrite(filepath, text)
     with open(filepath) as f:
         text_read = f.read()
     self.assertTrue(os.path.isdir(dirpath))
     shutil.rmtree(path.temppath('foo'))
     self.assertEqual(text_read, text)
Beispiel #5
0
    def setUp(self):
        self.blog_path = path.temppath('blog')
        self.site_path = path.temppath('site')
        os.makedirs(self.blog_path)

        with open(os.path.join(self.blog_path, 'foo.txt'), 'w') as f:
            f.write('Foo')
        with open(os.path.join(self.blog_path, 'bar.txt'), 'w') as f:
            f.write('Bar')
        with open(os.path.join(self.blog_path, '2018-01-01-foo.txt'), 'w') as f:
            f.write('Foo')
        with open(os.path.join(self.blog_path, '2018-01-02-bar.txt'), 'w') as f:
            f.write('Bar')
Beispiel #6
0
    def setUp(self):
        self.blog_path = path.temppath('blog')
        self.undated_path = os.path.join(self.blog_path, 'foo.txt')
        self.dated_path = os.path.join(self.blog_path, '2018-01-01-foo.txt')
        self.long_post_path = os.path.join(self.blog_path, 'bar.txt')
        self.normal_post_path = os.path.join(self.blog_path, 'baz.txt')
        self.md_post_path = os.path.join(self.blog_path, 'qux.md')
        self.no_md_post_path = os.path.join(self.blog_path, 'qux.txt')

        os.makedirs(self.blog_path)

        with open(self.undated_path, 'w') as f:
            f.write('hello world')

        with open(self.dated_path, 'w') as f:
            f.write('hello world')

        with open(self.long_post_path, 'w') as f:
            self.long_text = '  \n'.join('word' + str(i) for i in range(50))
            f.write(self.long_text)

        with open(self.normal_post_path, 'w') as f:
            f.write('<!-- a: 1 -->\n<!-- b: 2 -->\nFoo')

        with open(self.md_post_path, 'w') as f:
            f.write('*Foo*')

        with open(self.no_md_post_path, 'w') as f:
            f.write('*Foo*')
Beispiel #7
0
    def test_move_existing_file(self):
        src = os.path.join(path.temppath(), 'foo.txt')
        dst = os.path.join(path.temppath(), 'bar.txt')
        with open(src, 'w') as f:
            f.write('foo')

        path.move(src, dst)
        self.assertFalse(os.path.isfile(src))
        self.assertTrue(os.path.isfile(dst))

        with open(dst) as f:
            text = f.read()

        os.remove(dst)

        self.assertEqual(text, 'foo')
 def test_fwrite(self):
     text = 'baz\nqux\n'
     filepath = path.temppath('foo.txt')
     makesite.fwrite(filepath, text)
     with open(filepath) as f:
         text_read = f.read()
     os.remove(filepath)
     self.assertEqual(text_read, text)
 def test_fread(self):
     text = 'foo\nbar\n'
     filepath = path.temppath('foo.txt')
     with open(filepath, 'w') as f:
         f.write(text)
     text_read = makesite.fread(filepath)
     os.remove(filepath)
     self.assertEqual(text_read, text)
Beispiel #10
0
    def test_move_existing_dir(self):
        src = os.path.join(path.temppath(), 'foo')
        srcf = os.path.join(src, 'foo.txt')
        dst = os.path.join(path.temppath(), 'bar')
        dstf = os.path.join(dst, 'foo.txt')

        os.makedirs(src)
        with open(srcf, 'w') as f:
            f.write('foo')

        path.move(src, dst)
        self.assertFalse(os.path.isdir(src))
        self.assertTrue(os.path.isdir(dst))

        with open(dstf) as f:
            text = f.read()

        shutil.rmtree(dst)

        self.assertEqual(text, 'foo')
Beispiel #11
0
    def setUp(self):
        self.blog_path = path.temppath('blog')
        self.undated_path = os.path.join(self.blog_path, 'foo.txt')
        self.dated_path = os.path.join(self.blog_path, '2018-01-01-foo.txt')
        self.normal_post_path = os.path.join(self.blog_path, 'baz.txt')
        self.md_post_path = os.path.join(self.blog_path, 'qux.md')
        self.no_md_post_path = os.path.join(self.blog_path, 'qux.txt')

        os.makedirs(self.blog_path)

        with open(self.undated_path, 'w') as f:
            f.write('hello world')

        with open(self.dated_path, 'w') as f:
            f.write('hello world')

        with open(self.normal_post_path, 'w') as f:
            f.write('<!-- a: 1 -->\n<!-- b: 2 -->\nFoo')

        with open(self.md_post_path, 'w') as f:
            f.write('*Foo*')

        with open(self.no_md_post_path, 'w') as f:
            f.write('*Foo*')
Beispiel #12
0
 def setUp(self):
     self.site_path = path.temppath('site')
Beispiel #13
0
 def test_temppath(self):
     self.assertTrue(path.temppath())
Beispiel #14
0
 def test_move_missing_dir(self):
     src = os.path.join(path.temppath(), 'foo')
     dst = os.path.join(path.temppath(), 'bar')
     path.move(src, dst)
     self.assertFalse(os.path.isdir(src))
     self.assertFalse(os.path.isdir(dst))
Beispiel #15
0
 def test_move_missing_file(self):
     src = os.path.join(path.temppath(), 'foo.txt')
     dst = os.path.join(path.temppath(), 'bar.txt')
     path.move(src, dst)
     self.assertFalse(os.path.isfile(src))
     self.assertFalse(os.path.isfile(dst))