예제 #1
0
파일: file_test.py 프로젝트: rudimk/luigi
    def test_unicode(self):
        t = File(self.path)
        with t.open('w') as b:
            b.write(u"bar")

        with t.open('r') as b:
            self.assertEqual(b.read(), u'bar')
예제 #2
0
파일: file_test.py 프로젝트: rudimk/luigi
 def test_close(self):
     t = File(self.path)
     p = t.open('w')
     print('test', file=p)
     self.assertFalse(os.path.exists(self.path))
     p.close()
     self.assertTrue(os.path.exists(self.path))
예제 #3
0
파일: file_test.py 프로젝트: andrefsp/luigi
 def test_close(self):
     t = File(self.path)
     p = t.open('w')
     print >> p, 'test'
     self.assertFalse(os.path.exists(self.path))
     p.close()
     self.assertTrue(os.path.exists(self.path))
예제 #4
0
파일: file_test.py 프로젝트: rudimk/luigi
 def test_write_cleanup_with_error(self):
     t = File(self.path)
     try:
         with t.open('w'):
             raise Exception('something broke')
     except:
         pass
     self.assertFalse(t.exists())
예제 #5
0
 def test_write_cleanup_with_error(self):
     t = File(self.path)
     try:
         with t.open('w'):
             raise Exception('something broke')
     except:
         pass
     self.assertFalse(t.exists())
예제 #6
0
파일: file_test.py 프로젝트: rudimk/luigi
 def test_text(self):
     t = File(self.path, luigi.format.UTF8)
     a = u'我éçф'
     with t.open('w') as f:
         f.write(a)
     with t.open('r') as f:
         b = f.read()
     self.assertEqual(a, b)
예제 #7
0
    def test_write_cleanup_no_close(self):
        t = File(self.path)

        def context():
            f = t.open('w')
            f.write('stuff')
        context()
        gc.collect()  # force garbage collection of f variable
        self.assertFalse(t.exists())
예제 #8
0
    def test_write_cleanup_no_close(self):
        t = File(self.path)

        def context():
            f = t.open('w')
            f.write('stuff')
        context()
        gc.collect()  # force garbage collection of f variable
        self.assertFalse(t.exists())
예제 #9
0
파일: file_test.py 프로젝트: rudimk/luigi
    def test_del(self):
        t = File(self.path)
        p = t.open('w')
        print('test', file=p)
        tp = p.tmp_path
        del p

        self.assertFalse(os.path.exists(tp))
        self.assertFalse(os.path.exists(self.path))
예제 #10
0
파일: file_test.py 프로젝트: andrefsp/luigi
    def test_del(self):
        t = File(self.path)
        p = t.open('w')
        print >> p, 'test'
        tp = p.tmp_path
        del p

        self.assertFalse(os.path.exists(tp))
        self.assertFalse(os.path.exists(self.path))
예제 #11
0
파일: file_test.py 프로젝트: rudimk/luigi
    def test_del_with_Text(self):
        t = File(self.path, luigi.format.UTF8)
        p = t.open('w')
        print(u'test', file=p)
        tp = p.tmp_path
        del p

        self.assertFalse(os.path.exists(tp))
        self.assertFalse(os.path.exists(self.path))
예제 #12
0
파일: file_test.py 프로젝트: ChrisBg/luigi
 def test_move(self):
     t = File(self.path)
     f = t.open('w')
     test_data = 'test'
     f.write(test_data)
     f.close()
     self.assertTrue(os.path.exists(self.path))
     self.assertFalse(os.path.exists(self.copy))
     t.move(self.copy)
     self.assertFalse(os.path.exists(self.path))
     self.assertTrue(os.path.exists(self.copy))
예제 #13
0
파일: file_test.py 프로젝트: rudimk/luigi
    def test_format_chain_reverse(self):
        t = File(self.path, luigi.format.UTF8 >> luigi.format.Gzip)

        f = gzip.open(self.path, 'wb')
        f.write(b'\xe6\x88\x91\xc3\xa9\r\n\xc3\xa7\xd1\x84')
        f.close()

        with t.open('r') as f:
            b = f.read()

        self.assertEqual(u'我é\nçф', b)
예제 #14
0
파일: file_test.py 프로젝트: rudimk/luigi
 def test_move(self):
     t = File(self.path)
     f = t.open('w')
     test_data = 'test'
     f.write(test_data)
     f.close()
     self.assertTrue(os.path.exists(self.path))
     self.assertFalse(os.path.exists(self.copy))
     t.move(self.copy)
     self.assertFalse(os.path.exists(self.path))
     self.assertTrue(os.path.exists(self.copy))
예제 #15
0
파일: file_test.py 프로젝트: ChrisBg/luigi
 def test_copy(self):
     t = File(self.path)
     f = t.open('w')
     test_data = 'test'
     f.write(test_data)
     f.close()
     self.assertTrue(os.path.exists(self.path))
     self.assertFalse(os.path.exists(self.copy))
     t.copy(self.copy)
     self.assertTrue(os.path.exists(self.path))
     self.assertTrue(os.path.exists(self.copy))
     self.assertEqual(t.open('r').read(), File(self.copy).open('r').read())
예제 #16
0
파일: file_test.py 프로젝트: andrefsp/luigi
    def test_tmp(self):
        t = File(is_tmp=True)
        p = t.open('w')
        print >> p, 'test'
        p.close()

        path = t.path
        self.assertTrue(os.path.exists(path))
        q = t.open('r')
        self.assertEqual(q.readline(), 'test\n')
        q.close()
        del t # should remove the underlying file
        self.assertFalse(os.path.exists(path))
예제 #17
0
파일: file_test.py 프로젝트: rudimk/luigi
    def test_format_chain(self):
        UTF8WIN = luigi.format.TextFormat(encoding='utf8', newline='\r\n')
        t = File(self.path, UTF8WIN >> luigi.format.Gzip)
        a = u'我é\nçф'

        with t.open('w') as f:
            f.write(a)

        f = gzip.open(self.path, 'rb')
        b = f.read()
        f.close()

        self.assertEqual(b'\xe6\x88\x91\xc3\xa9\r\n\xc3\xa7\xd1\x84', b)
예제 #18
0
파일: file_test.py 프로젝트: smar10/luigi
    def test_tmp(self):
        t = File(is_tmp=True)
        p = t.open('w')
        print >> p, 'test'
        p.close()

        path = t.path
        self.assertTrue(os.path.exists(path))
        q = t.open('r')
        self.assertEqual(q.readline(), 'test\n')
        q.close()
        del t  # should remove the underlying file
        self.assertFalse(os.path.exists(path))
예제 #19
0
파일: file_test.py 프로젝트: rudimk/luigi
    def test_format_newline(self):
        t = File(self.path, luigi.format.SysNewLine)

        with t.open('w') as f:
            f.write(b'a\rb\nc\r\nd')

        with t.open('r') as f:
            b = f.read()

        with open(self.path, 'rb') as f:
            c = f.read()

        self.assertEqual(b'a\nb\nc\nd', b)
        self.assertEqual(b'a\r\nb\r\nc\r\nd', c)
예제 #20
0
파일: file_test.py 프로젝트: ChrisBg/luigi
    def test_format_injection(self):
        class CustomFormat(luigi.format.Format):
            def pipe_reader(self, input_pipe):
                input_pipe.foo = "custom read property"
                return input_pipe

            def pipe_writer(self, output_pipe):
                output_pipe.foo = "custom write property"
                return output_pipe

        t = File(self.path, format=CustomFormat())
        with t.open("w") as f:
            self.assertEqual(f.foo, "custom write property")

        with t.open("r") as f:
            self.assertEqual(f.foo, "custom read property")
예제 #21
0
파일: file_test.py 프로젝트: rudimk/luigi
    def test_format_injection(self):
        class CustomFormat(luigi.format.Format):
            def pipe_reader(self, input_pipe):
                input_pipe.foo = "custom read property"
                return input_pipe

            def pipe_writer(self, output_pipe):
                output_pipe.foo = "custom write property"
                return output_pipe

        t = File(self.path, format=CustomFormat())
        with t.open("w") as f:
            self.assertEqual(f.foo, "custom write property")

        with t.open("r") as f:
            self.assertEqual(f.foo, "custom read property")
예제 #22
0
파일: file_test.py 프로젝트: rudimk/luigi
 def test_copy(self):
     t = File(self.path)
     f = t.open('w')
     test_data = 'test'
     f.write(test_data)
     f.close()
     self.assertTrue(os.path.exists(self.path))
     self.assertFalse(os.path.exists(self.copy))
     t.copy(self.copy)
     self.assertTrue(os.path.exists(self.path))
     self.assertTrue(os.path.exists(self.copy))
     self.assertEqual(t.open('r').read(), File(self.copy).open('r').read())
예제 #23
0
파일: file_test.py 프로젝트: rudimk/luigi
    def test_gzip(self):
        t = File(self.path, luigi.format.Gzip)
        p = t.open('w')
        test_data = b'test'
        p.write(test_data)
        print(self.path)
        self.assertFalse(os.path.exists(self.path))
        p.close()
        self.assertTrue(os.path.exists(self.path))

        # Using gzip module as validation
        f = gzip.open(self.path, 'r')
        self.assertTrue(test_data == f.read())
        f.close()

        # Verifying our own gzip reader
        f = File(self.path, luigi.format.Gzip).open('r')
        self.assertTrue(test_data == f.read())
        f.close()
예제 #24
0
파일: file_test.py 프로젝트: rudimk/luigi
    def test_bzip2(self):
        t = File(self.path, luigi.format.Bzip2)
        p = t.open('w')
        test_data = b'test'
        p.write(test_data)
        print(self.path)
        self.assertFalse(os.path.exists(self.path))
        p.close()
        self.assertTrue(os.path.exists(self.path))

        # Using bzip module as validation
        f = bz2.BZ2File(self.path, 'r')
        self.assertTrue(test_data == f.read())
        f.close()

        # Verifying our own bzip2 reader
        f = File(self.path, luigi.format.Bzip2).open('r')
        self.assertTrue(test_data == f.read())
        f.close()
예제 #25
0
파일: file_test.py 프로젝트: andrefsp/luigi
    def test_gzip(self):
        t = File(self.path, luigi.format.Gzip)
        p = t.open('w')
        test_data = 'test'
        p.write(test_data)
        print self.path
        self.assertFalse(os.path.exists(self.path))
        p.close()
        self.assertTrue(os.path.exists(self.path))

        # Using gzip module as validation
        f = gzip.open(self.path, 'rb')
        self.assertTrue(test_data == f.read())
        f.close()

        # Verifying our own gzip reader
        f = File(self.path, luigi.format.Gzip).open('r')
        self.assertTrue(test_data == f.read())
        f.close()
예제 #26
0
파일: file_test.py 프로젝트: ChrisBg/luigi
    def test_bzip2(self):
        t = File(self.path, luigi.format.Bzip2)
        p = t.open('w')
        test_data = 'test'
        p.write(test_data)
        print self.path
        self.assertFalse(os.path.exists(self.path))
        p.close()
        self.assertTrue(os.path.exists(self.path))

        # Using bzip module as validation
        f = bz2.BZ2File(self.path, 'rb')
        self.assertTrue(test_data == f.read())
        f.close()

        # Verifying our own bzip2 reader
        f = File(self.path, luigi.format.Bzip2).open('r')
        self.assertTrue(test_data == f.read())
        f.close()