Exemplo n.º 1
0
 def test_next(self):                   
     """ Next provides another SmartURL instance. """
     linklist=urllib2.urlopen("file://%s"%(self.linklistPath))
     linklistInstance=LinklistAdaptor()
     linklistInstance.connectLinklistFile(linklist)
     self.textLinklistParserInstance.connectLinklistAdaptor(linklistInstance)
     next=self.textLinklistParserInstance.next()
     # 026 If this test fails, check if first line of linklist is not commented out.
     self.assertTrue(isinstance(next,SmartURL))
Exemplo n.º 2
0
class LinklistTest(unittest.TestCase):
    
    def setUp(self):
        self.linklistInstance=LinklistAdaptor()
        debugMock=Mock()
        settings=Settings()
        self.linklistInstance.debug=debugMock
        self.linklistInstance.settings=settings
        self.linklistPath="/media/KINGSTON/Sumid/linklist/prelinklist25.txt"
        
    def tearDown(self):
        self.linklistInstance=None
        

    def test_nextRaw_noLinklist(self):
        """ If there's no linklist connected, nextRaw raises error."""
        # Suppose thers's no linlist until I connect it.
        self.assertRaises(BufferError,self.linklistInstance.nextRaw)
        self.linklistInstance.linklist=None
        self.assertRaises(BufferError,self.linklistInstance.nextRaw,)
        
    def test_nextRaw_correctLinklist(self):
        """ nextRaw returns a line without any modification, when linklist is set correctly. """
        #linklistPath="/media/KINGSTON/Sumid/linklist/prelinklist25.txt"
        # First peek what is first line of the linklist.
        linklistFile=file(self.linklistPath,'r')
        firstLine=linklistFile.readline()
        linklistFile.close()
        # Set-up URL linklist for test.
        linklistURL="file://%s"%(self.linklistPath)
        linklistFile=urllib2.urlopen(linklistURL)
        self.linklistInstance.connectLinklistFile(linklistFile)
        line=self.linklistInstance.nextRaw()
        # The URL test.
        self.assertEqual(firstLine,line)
        # Set-up file linklist for test.
        linklistFile=file(self.linklistPath,'r')
        self.linklistInstance.connectLinklistFile(linklistFile)
        line=self.linklistInstance.nextRaw()
        #The file test
        self.assertEqual(firstLine,line)
        
    def test_connectLinklistFile_wrongInput(self):
        """ If the input of connectLinklistFile() is not a file-like object, exception is raised."""
        self.assertRaises(AttributeError,self.linklistInstance.connectLinklistFile,"/This/is/a/string")
        self.assertRaises(AttributeError,self.linklistInstance.connectLinklistFile,["This","is","a","list"])
        self.assertRaises(AttributeError,self.linklistInstance.connectLinklistFile,{"This":"is","a":"dict"})
        self.assertRaises(AttributeError,self.linklistInstance.connectLinklistFile,object())
        
    def test_connectLinklistFile_correctInput(self):
        """ If the input of connectLinklistFile() is a file-like object, then self.linklist link to it is created. """
        #linklistPath="/media/KINGSTON/Sumid/linklist/prelinklist25.txt"
        linklistURL="file://%s"%(self.linklistPath)
        linklistFile=urllib2.urlopen(linklistURL)
        self.linklistInstance.connectLinklistFile(linklistFile)
        self.assertEqual(self.linklistInstance.linklist.geturl(),linklistURL)
        linklistFile=file(self.linklistPath,'r')
        self.linklistInstance.connectLinklistFile(linklistFile)
        self.assertEqual(self.linklistInstance.linklist.name,self.linklistPath)
Exemplo n.º 3
0
Arquivo: bow.py Projeto: xhujerr/Sumid
    settings = Settings()
    Shared.settings = settings
    settings.mainINIFilePath = mainINIFilePath
    settings.loadAdaptive("all")
    settings.loadFromINI(mainINIFilePath)
    debug = Debug(settings)
    Shared.debug = debug

    factory = FactoryMethod()
    settings.pathStorage = factory.create(eval(settings.platform + "PathStorage"))
    factory.sharedRef.pathStorage = settings.pathStorage

    files = FilesAdaptorComplex()
    settings.connectFilesAdaptor(files)
    linklistAdaptor = LinklistAdaptor()
    linklistAdaptor.connectLinklistFile(files.linklist)

    textLinklistParser = TextLinklistParser()
    textLinklistParser.connectLinklistAdaptor(linklistAdaptor)

    debug.ThreadAwareLogger.info("Basic initialization complete.")

    counters = CounterManager()
    files.connectDB()

    dummyQueue = Queue()  # 026 This is to bypass non-existence of hydra. Fast & ugly.
    countersQueue = Queue()
    countersQueueCondition = threading.Condition()

    # AbstractProducer(inputQueue,outputQueue,inputCondition,outputCondition,**kwargs):
    # bowBuilderSimple=BOWBuilderSimple(dummyQueue,countersQueue,None,countersQueueCondition,parserInstance=textLinklistParser)