[python 2.4] unable to construct tuple with one item

2007-05-06 Thread Vyacheslav Maslov

Hi, all!

I found out different behavior of python interpeter related to tuples and
lists with one item only.

I have simple example

print type(())


it's ok, we have just constructed empty tuple


print type((4))


but when i add exactly one item to my tuple i get atomaric int instead of
tuple!!! why?


print type((4,))


this problem can be avoided by adding comma after first item


print type([4])


but finally, python constructs list with one item without any problem.

So, the main question is why using syntax like [X] python constuct list with
one item, but when i try to construct tuple with one item using similar
syntax (X) python do nothing?

P.S. python 2.4
-- 
http://mail.python.org/mailman/listinfo/python-list

default test method name in unittest framework

2007-05-06 Thread Vyacheslav Maslov

Hi, all!

i have question related to python's unit testing framework.

Take a look at unittest.TestCase class. The main method which contains all
code related to test case execution have name "run". But in the same time
constructor of unittest.TestCase class have param methodName with default
value "runTest", not "run"! Why? This leads to AttributeError exception if i
do not explicitly set methodName to "run" during TestCase initialization.
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: unable to construct tuple with one item

2007-05-06 Thread Vyacheslav Maslov

Guys, thanks a lot for you answers
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Help creating Tiger hash function in Python

2007-05-06 Thread Vyacheslav Maslov
> I am a Uni student and for a project in Information Systems Security due
> in just under two weeks, I have tried to make a Python version of the
> Biham / Anderson Tiger Hash function. I have put the original C source
> and my two files Tiger.py and doHash.py on my website:
> 
> http://www.users.on.net/~mlivingstone/
> 
> My problems are doubtless basic since I have been teaching myself
> Python. My best knowledge is Java :-(
> 
> Firstly, in doHash.py, I cannot invoke tiger() without getting unbounded
> errors and / or complaints about no such method.

First of all you should create an instance of you Tiger class, you try 
to do this by line:
x = Tiger.Tiger

But this is wrong, because you should call constructor and pass all 
necessary parameters, in very simple case:
x = Tiger.Tiger() (if there is no constructor parameters)

-- 
Vyacheslav Maslov
SWsoft, Inc.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: default test method name in unittest framework

2007-05-07 Thread Vyacheslav Maslov

Yes, i general you are right. I meant following case, please look at my
example

Suppose i have following simple test case:

import unittest

class SomeTest(unittest.TestCase):

   def testAdd(self):
   self.assertEqual(2+2,4)

if __name__=="__main__":
   unittest.TextTestRunner().run(SomeTest())

this code produce following exception:
ValueError: no such test method in : runTest

Because default test method name is "run", but TestCase class have
constructor parameter testMethod with default value "runTest" not "run"!

As result i always should explicitly pass testMethod name when create object
of test case class:
   unittest.TextTestRunner().run(SomeTest("run"))

Why i should do this?

2007/5/7, Gabriel Genellina <[EMAIL PROTECTED]>:


En Sun, 06 May 2007 22:17:44 -0300, Vyacheslav Maslov
<[EMAIL PROTECTED]> escribió:

> i have question related to python's unit testing framework.
>
> Take a look at unittest.TestCase class. The main method which contains
> all
> code related to test case execution have name "run". But in the same
time
> constructor of unittest.TestCase class have param methodName with
default
> value "runTest", not "run"! Why? This leads to AttributeError exception
> if i
> do not explicitly set methodName to "run" during TestCase
initialization.

No: method run is used by the framework, it internally calls the setUp,
tearDown, etc. You don't have to override run (you must not override
run!), instead, you provide the runTest method in your class.
Furthermore, instead of many similar TestCase classes, you can write a
single class with many methods named testXXX, and they will be found and
used by a TestLoader.

--
Gabriel Genellina

--
http://mail.python.org/mailman/listinfo/python-list

-- 
http://mail.python.org/mailman/listinfo/python-list

Re: assisging multiple values to a element in dictionary

2007-05-07 Thread Vyacheslav Maslov
>I have a dictionary which is something like this:
> id_lookup={
> 16:'subfunction',
> 26:'dataId',
> 34:'parameterId',
> 39:'subfunction',
> 44:'dataPackageId',
> 45:'parameterId',
> 54:'subfunction',
> 59:'dataId',
> 165:'subfunction',
> 169:'subfunction',
> 170:'dataPackageId',
> 174:'controlParameterId'
> }
>  How do i assign multiple values to the key here.Like i want the
> key 170 to take either the name 'dataPackageID' or the name
> 'LocalId'.
In general dictionary define strong relation between keys and values, 
key should have only one associated value, but in your case value can be 
  a tuple or list.

Anyway, i think that your question contradict to dictionary concept, 
because is impossilbe to assign for some key multiple values.


-- 
Vyacheslav Maslov
-- 
http://mail.python.org/mailman/listinfo/python-list


multi threaded SimpleXMLRPCServer

2007-05-14 Thread Vyacheslav Maslov
Hi, all!

I need multi threaded version of SimpleXMLRPCServer. Does python library 
already have implementation of this one? Or i need to implement multi 
threading by myself?

Which way is the simpliest?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: using google search api for python

2007-05-23 Thread Vyacheslav Maslov
Gerardo Herzig wrote:
> Hi all. Im looking for the pyGoogle for making google searchs y a python 
> script. The thing is, all im founding is an AJAX api, but the 
> application ill use is NOT a web app. So, someone know if there is a 
> pure python api that i can download and use?
> 
> Thanks!
> Gerardo
http://www.ibm.com/developerworks/webservices/library/ws-pyth14/

-- 

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Large Amount of Data

2007-05-25 Thread Vyacheslav Maslov
Larry Bates wrote:
> Jack wrote:
>> Thanks for the replies!
>>
>> Database will be too slow for what I want to do.
>>
>> "Marc 'BlackJack' Rintsch" <[EMAIL PROTECTED]> wrote in message 
>> news:[EMAIL PROTECTED]
>>> In <[EMAIL PROTECTED]>, Jack wrote:
>>>
>>>> I need to process large amount of data. The data structure fits well
>>>> in a dictionary but the amount is large - close to or more than the size
>>>> of physical memory. I wonder what will happen if I try to load the data
>>>> into a dictionary. Will Python use swap memory or will it fail?
>>> What about putting the data into a database?  If the keys are strings the
>>> `shelve` module might be a solution.
>>>
>>> Ciao,
>>> Marc 'BlackJack' Rintsch 
>>
> Purchase more memory.  It is REALLY cheap these days.
Not a solution at all. What about if amount of data exceed architecture 
memory limits? i.e. 4Gb at 32bit.

Better solution is to use database for data storage/processing

-- 
Vyacheslav Maslov
-- 
http://mail.python.org/mailman/listinfo/python-list


reliable unit test logging

2007-10-01 Thread Vyacheslav Maslov
Hi all!

I have many many many python unit test, which are used for testing some 
remote web service.

The most important issue here is logging of test execution process and 
result. I strongly need following:
1. start/end timestamp for each test case (most important)
2. immediate report about exceptions (stacktrace)
3. it will be nice to use logging module for output

I have investigated some extension for standard unittest module, e.g. 
testoob, nose, etc. They have very nice features but they does not 
satisfy first requirement in my list - test execution logs not doesn't 
contain timestamps.

Can someone explain my why so simple feature like logging of timestamps 
during test execution was not implemented in any extension?

Also i need some advices about how i can implement timestamps logging 
myself. I think proper way is develop customized TextTestRunner and use 
logging module instead of "print"s. Is it right way or there is more simply?

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: reliable unit test logging

2007-10-02 Thread Vyacheslav Maslov
Ben Finney wrote:
> Vyacheslav Maslov <[EMAIL PROTECTED]> writes:
> 
>> I have many many many python unit test, which are used for testing
>> some remote web service.
> 
> Part of your confusion comes from the fact that "test a remote
> service" isn't what a unit test does.
> 
> A unit test is one that executes a very *limited* part of the code: it
> tests a code unit, not the whole system, and makes a simple set of
> assertions about the result. If there are accesses to remote services
> over the network, that's far beyond the scope of a unit test.
> 
> I don't doubt that you may be using the Python standard library module
> 'unittest' to perform these tests. But they're not unit tests; they're
> integration tests, or system tests, or performance tests, or something
> else.
> 
>> Can someone explain my why so simple feature like logging of
>> timestamps during test execution was not implemented in any
>> extension?
> 
> Probably because the most important thing to know for the purpose of a
> unit test is whether the yes/no assertions were violated. Knowing when
> the tests start and finish isn't interesting. If start and finish
> times *are* interesting for your tests, you're *not* doing unit
> testing, but some other form of testing like performance tests.
I understand your opinion, you are right, i use unit tests for some 
other kind of work. But anyway it works and produce good results for 
project.

> Untested code, that should give you enough to try it out yourself:
Thanks i will look into this.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: reliable unit test logging

2007-10-03 Thread Vyacheslav Maslov
Ben Finney wrote:
> Vyacheslav Maslov <[EMAIL PROTECTED]> writes:
> 
>> I understand your opinion
> 
> Hopefully you mean "explanation", not "opinion". I gave what appear to
> me to be facts, not opinion, about the definition of a unit test.
Yes, i meant "explanation".

I have one more question related to logging module, not unit test. I use 
FileHandler to append information to file log, in fact location of log 
file depends on some external factor and is calculated during 
initialization. Furthermore i want to use configuration file because it 
is comfortable way. So i need way to define in configuration file some 
variable which should evaluated during logging system initialization, i 
try following way:

[handler_hand02]
class=FileHandler
level=NOTSET
formatter=form01
args=(logFileDir+"myfile.log","a",)
logFileDir is defined in scope of module which call 
logging.config.fileConfig()

and it produces "name 'logFileDir' is not defined" exception. As i 
understand this happens because inside logging module variable 
logFileDir is not visible. How i can avoid this?

Thanks!



-- 
-- 
http://mail.python.org/mailman/listinfo/python-list


PyDev 1.3.9 code compleition trouble

2007-10-09 Thread Vyacheslav Maslov
Hi!

I use Pydev 1.3.9 and notice issue related to code completion. I give an 
example

BaseClass.py:

class BaseClass:
 def someMethod(x):
 return x+x

DerivedClass.py:

import BaseClass

class DerivedClass(BaseClass.BaseClass):
 def newMethod(self):
 print self.someMethod(4)


I try to use code completion in class DerivedClass inside method 
"newMethod", after typing "self." and pushing ctrl+space completion 
dialog propose substitution only for method "newMethod". However, i 
expect that method defined in BaseClass called "someMethod" should be 
proposed also as well. Why this doesn't work?
-- 
http://mail.python.org/mailman/listinfo/python-list