test_document.py :  » IDE » PIDA » pida-0.6beta3 » tests » core » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » IDE » PIDA 
PIDA » pida 0.6beta3 » tests » core » test_document.py

import os
from pida.core.document import Document
from pida.core.document import DocumentException
#from pida.core.testing import test, assert_equal, assert_notequal

from pida.utils.testing.mock import Mock

from unittest import TestCase
from tempfile import mktemp

def document(*k, **kw):
    mock = Mock()
    mock.log = Mock()
    return document_class(mock, *k, **kw)

def c():
    tmp = mktemp()
    f = open(tmp, 'w')
    txt ="""Hello I am a document
               vlah blah"""
    f.write(txt)
    f.close()
    doc = document(filename=tmp)
    return doc, tmp, txt

def d(x):
    os.remove(x)


class DocumentTest(TestCase):

    def test_new_document(self):
        doc = document()
        self.assertEqual(doc.is_new, True)
        self.assertEqual(doc.filename, None)

    def test_unnamed_document(self):
        doc = document()
        self.assertEqual(doc.filename, None)


    def test_new_index(self):
        doc = document()
        doc2 = document()
        self.assertNotEqual(doc.newfile_index, doc2.newfile_index)

    def test_no_project(self):
        doc = document()
        self.assertEqual(doc.project_name, '')

    def test_unique_id(self):
        doc = document()
        doc2 = document()
        self.assertNotEqual(doc.unique_id, doc2.unique_id)

    def test_real_file(self):
        doc, tmp, txt = c()
        self.assertEqual(doc.filename, tmp)
        d(tmp)

    def test_file_text(self):
        doc, tmp, txt = c()
        self.assertEqual(doc.content, txt)
        d(tmp)

    def test_file_lines(self):
        doc, tmp, txt = c()
        self.assertEqual(len(doc.lines), 2)
        d(tmp)

    def test_file_len(self):
        doc, tmp, txt = c()
        self.assertEqual(doc.filesize, len(txt))
        d(tmp)

    def test_directory(self):
        doc, tmp, txt = c()
        self.assertEqual(doc.directory, '/tmp')
        d(tmp)


    def test_directory_basename(self):
        doc, tmp, txt = c()
        self.assertEqual(doc.directory_basename, 'tmp')
        d(tmp)


    def test_basename(self):
        doc, tmp, txt = c()
        self.assertEqual(doc.basename, os.path.basename(tmp))
        d(tmp)

    def test_file_missing_load(self):
        doc = document(filename='/this_is_hopefully_missing_for_sure')
        doc._load()

    def test_file_missing_stat(self):
        doc = document(filename='/this_is_hopefully_missing_for_sure')
        self.assertEqual(doc.stat, (0,)*10)

    def test_repr_new(self):
        from pida.core import document
        doc = document()
        self.assertEqual(repr(doc), '<New Document %d (%s)>'%(document_module.new_file_index-1, id(doc)))

    def test_repr_known(self):
        doc = document(filename='test')
        self.assertEqual(repr(doc), "<Document '%s' (%s)>" %
                                    (os.path.abspath('test'), id(doc)))
        
    def test_unicode_new(self):
        from pida.core import document
        doc = document()
        self.assertEqual(unicode(doc), u'Untitled (%d)' %(document_module.new_file_index-1))
    
    def test_unicode_knows(self):
        doc = document(filename='test')
        self.assertEqual(unicode(doc), doc.basename)
        
    def test_content_nonlife(self):
        import tempfile
        name = tempfile.mkstemp(suffix="pida-test")[1]
        d = document(filename=name)
        STR1 = u'i write something'
        STR2 = u'other text too'
        d.content = STR1
        self.assertEqual(d.content, STR1)
        del d
        d = document(filename=name)
        self.assertEqual(d.content, STR1)
        d.content = STR2
        self.assertEqual(d.content, STR2)
        d.content += STR1
        self.assertEqual(d.content, "%s%s" %(STR2, STR1))
        del d
        d = document(filename=name)
        self.assertEqual(d.content, "%s%s" %(STR2, STR1))
        os.unlink(name)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.