Re: non-blocking getkey?

2015-12-10 Thread Ulli Horlacher
Ulli Horlacher  wrote:

> > But... is there a windows program with which one can select files and the
> > result is written to STDOUT?
> 
> Found it:
> 
> from Tkinter import Tk
> from tkFileDialog import askopenfilename
> 
> Tk().withdraw()
> file = askopenfilename()

My users do not like it :-(
They want to drag&drop files.
Therefore I have added it as another option to enter files:

[f] select a file
[d] select a directory
[e] enter a file or directory (with drag&drop or copy&paste)

With [f] starts askopenfilename and [d] starts askdirectory

The problem with [e] is: my users do not press ENTER after pasting.

My idea now is: instead of raw_input() I use a get_paste() function, which
reads input character for input character and after a (say) 1 s timeout it
returns the string. Pasting a string with the mouse is rather fast, there
should be no big delay between the characters.

How can I implement such a get_paste() function?
I need a non-blocking getkey() function.

It must work on Windows and Linux.


-- 
Ullrich Horlacher  Server und Virtualisierung
Rechenzentrum IZUS/TIK E-Mail: horlac...@tik.uni-stuttgart.de
Universitaet Stuttgart Tel:++49-711-68565868
Allmandring 30aFax:++49-711-682357
70550 Stuttgart (Germany)  WWW:http://www.tik.uni-stuttgart.de/

-- 
Ullrich Horlacher  Server und Virtualisierung
Rechenzentrum IZUS/TIK E-Mail: horlac...@tik.uni-stuttgart.de
Universitaet Stuttgart Tel:++49-711-68565868
Allmandring 30aFax:++49-711-682357
70550 Stuttgart (Germany)  WWW:http://www.tik.uni-stuttgart.de/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: non-blocking getkey?

2015-12-10 Thread Christian Gollwitzer

Am 10.12.15 um 09:28 schrieb Ulli Horlacher:

Ulli Horlacher  wrote:

Found it:

 from Tkinter import Tk
 from tkFileDialog import askopenfilename

 Tk().withdraw()
 file = askopenfilename()


My users do not like it :-(
They want to drag&drop files.
Therefore I have added it as another option to enter files:

[f] select a file
[d] select a directory
[e] enter a file or directory (with drag&drop or copy&paste)



Well I know that you won't take my advice but.

There are standard protocols for drag'n'drop of files and folders on all 
three major platforms. Tk supports this using the optional TkDND module, 
which unfortunately isn't installed with a standard Python distribution. 
Beware there is a "Tkdnd" Python module which implements local 
Drag'n'drop only; you need the "real thing" from here


http://sourceforge.net/projects/tkdnd/

plus the correct Python bindings: Maybe this is the correct one: 
http://osdir.com/ml/python.tkinter/2005-07/msg0.html
I'm not sure - never used it from Python, only from Tcl. Using "the real 
thing" also allows you to accept multiple files/drectories dragged from 
the system file manager. Of course, you need a Tk main window to 
implement this, which you refused earlier.



With [f] starts askopenfilename and [d] starts askdirectory

The problem with [e] is: my users do not press ENTER after pasting.

My idea now is: instead of raw_input() I use a get_paste() function, which
reads input character for input character and after a (say) 1 s timeout it
returns the string. Pasting a string with the mouse is rather fast, there
should be no big delay between the characters.

How can I implement such a get_paste() function?
I need a non-blocking getkey() function.

It must work on Windows and Linux.


Raw tty input. You'll have to write two different versions for Windows 
and Linux. Sorry I can't help with that one.


Christian
--
https://mail.python.org/mailman/listinfo/python-list


Re: non-blocking getkey?

2015-12-10 Thread Christian Gollwitzer

Am 10.12.15 um 09:28 schrieb Ulli Horlacher:

Ulli Horlacher  wrote:
My users do not like it :-(
They want to drag&drop files.


Another cheap solution comes to mind: On windows, dropping files onto an 
icon on the desktop is interpreted as "launch the program with 
additional arguments", where the arguments are the file names. Maybe you 
could try interpreting the cmdline args first? I'm not so sure how it 
will work with non-ASCII characters, though. On Linux, you can probably 
also create simliar icons. The only drawback is that you start a new 
instance of your file manager each time.


Christian

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


tkinter cascaded menus, was Re: PyTk cascaded radiobuttons, howto?

2015-12-10 Thread Peter Otten
nickgeova...@gmail.com wrote:

> Using python 3.4.2.
> Tcl/tk example here is from /usr/share/tk8.5/demos/widget and
> .../menu.tcl. The way tcl/tk adds cascaded radiobuttons to a menu is like
> this: set m $w.menu.cascade
> $w.menu add cascade -label "Cascades" -menu $m -underline 0
> 
> $m add cascade -label "Radio buttons" -menu $w.menu.cascade.radio...
> set m $w.menu.cascade.radio
> $m add radio -label "Roman" -variable style...
> $m add radio -label "Italic" -variable style...
> 
> ...and so on.
> 
> My difficulty doing the same in PyTk is the following: When creating that
> uppermost cascade, you do something like menu.add_cascade(label =
> "Cascades") ...but there is no ability to save a usable reference to that
> top-level cascade. If I do so anyway and add a radiobutton to it, nothing
> appears, no errors either. What is the correct way to cascade radiobuttons
> from a cascaded menu in PyTk? ThanksNick

You build the inner menu and then add it to the outer.

After looking into the examples in the Demo/tkinter folder of the Python 2.7 
source distribution I came up with the following:

import tkinter
from tkinter import Menu

root = tkinter.Tk()

menubar = Menu(root)

editmenu = Menu(menubar)

editmenu.add_command(label="Cut")
editmenu.add_command(label="Copy")
editmenu.add_command(label="Paste")

fontmenu = Menu(editmenu, name="font")
fontmenu.add_command(label="Family")
fontmenu.add_command(label="Size")
editmenu.add_cascade(label="Font", menu=fontmenu)

colormenu = Menu(editmenu, name="color")
colormenu.add_radiobutton(label="Red")
colormenu.add_radiobutton(label="Yellow")
colormenu.add_radiobutton(label="Blue")
fontmenu.add_cascade(label="Color", menu=colormenu)

menubar.add_cascade(label="Edit", menu=editmenu)

root["menu"] = menubar
root.mainloop()


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


Re: non-blocking getkey?

2015-12-10 Thread Ulli Horlacher
Christian Gollwitzer  wrote:

> > My users do not like it :-(
> > They want to drag&drop files.
> > Therefore I have added it as another option to enter files:
> >
> >   [f] select a file
> >   [d] select a directory
> >   [e] enter a file or directory (with drag&drop or copy&paste)
> 
> 
> Well I know that you won't take my advice but.
> 
> There are standard protocols for drag'n'drop of files and folders on all 
> three major platforms. Tk supports this using the optional TkDND module, 
> which unfortunately isn't installed with a standard Python distribution. 

Then this is no-go.
My users cannot install any additional software.


-- 
Ullrich Horlacher  Server und Virtualisierung
Rechenzentrum IZUS/TIK E-Mail: horlac...@tik.uni-stuttgart.de
Universitaet Stuttgart Tel:++49-711-68565868
Allmandring 30aFax:++49-711-682357
70550 Stuttgart (Germany)  WWW:http://www.tik.uni-stuttgart.de/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: non-blocking getkey?

2015-12-10 Thread Ulli Horlacher
Christian Gollwitzer  wrote:

> Another cheap solution comes to mind: On windows, dropping files onto an 
> icon on the desktop is interpreted as "launch the program with 
> additional arguments", where the arguments are the file names.

Ohhh... great! This helps me a lot!


> Maybe you could try interpreting the cmdline args first?

I have implemented this since the beginning of the project :-)


> I'm not so sure how it will work with non-ASCII characters, 

My users have to test it. I do not have non-ASCII filenames.

-- 
Ullrich Horlacher  Server und Virtualisierung
Rechenzentrum IZUS/TIK E-Mail: horlac...@tik.uni-stuttgart.de
Universitaet Stuttgart Tel:++49-711-68565868
Allmandring 30aFax:++49-711-682357
70550 Stuttgart (Germany)  WWW:http://www.tik.uni-stuttgart.de/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Problems using celery and pyelasticsearch

2015-12-10 Thread nonami



On 07/12/2015 02:50, Laura Creighton wrote:

In a message of Mon, 07 Dec 2015 02:37:15 +0100, nonami writes:


Does anyone have any idea what could be going on or how I can further
inspect running tasks.

Not sure this will help, but it might ...
https://www.caktusgroup.com/blog/2013/10/30/using-strace-debug-stuck-celery-tasks/


This was really helpful Laura, thanks.
--
https://mail.python.org/mailman/listinfo/python-list


SystemError in python 2.5.4

2015-12-10 Thread Palpandi
Hi All,

I am getting the error mentioned below in python 2.5.4.

SystemError: \loewis\25\python\Objects\longobject.c:225: bad argument to 
internal function.

I also ran the same code in python 2.7.
There I am not getting this error.

I don't know which causes this error. Any solution for this?

Note: The error is coming from the method call findall(path).


Thanks.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: SystemError in python 2.5.4

2015-12-10 Thread Chris Angelico
On Thu, Dec 10, 2015 at 10:29 PM, Palpandi  wrote:
> Hi All,
>
> I am getting the error mentioned below in python 2.5.4.
>
> SystemError: \loewis\25\python\Objects\longobject.c:225: bad argument to 
> internal function.
>
> I also ran the same code in python 2.7.
> There I am not getting this error.
>
> I don't know which causes this error. Any solution for this?
>
> Note: The error is coming from the method call findall(path).
>

Interesting! What platform (OS, etc) are you running this on? Python
2.5 isn't supported any more, so you might have to talk to Red Hat or
someone. Alternatively, given that 2.7 doesn't have this problem, can
you simply write it off as an issue with the older Python, and use 2.7
instead?

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


IO Redirection to Console

2015-12-10 Thread austin aigbe
Hello,

I am trying to port the following C++ code for IO redirection to console.

// C++ (from Synfig)

void redirectIOToConsole()
{
int hConHandle;
HANDLE lStdHandle;
CONSOLE_SCREEN_BUFFER_INFO coninfo;
FILE *fp;

// allocate console
if( GetStdHandle(STD_OUTPUT_HANDLE) != INVALID_HANDLE_VALUE )
AllocConsole();
// set the screen buffer to be big enough to let us scroll text
GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &coninfo);
coninfo.dwSize.Y = MAX_LINES;
SetConsoleScreenBufferSize(GetStdHandle(STD_OUTPUT_HANDLE), 
coninfo.dwSize);
//redirect unbuffered STDOUT to the console
lStdHandle = GetStdHandle(STD_OUTPUT_HANDLE);
hConHandle = _open_osfhandle((intptr_t) lStdHandle, _O_TEXT);
fp = _fdopen( hConHandle, "w" );
*stdout = *fp;
setvbuf( stdout, NULL, _IONBF, 0 );
// redirect unbuffered STDIN to the console
lStdHandle = GetStdHandle(STD_INPUT_HANDLE);
hConHandle = _open_osfhandle((intptr_t) lStdHandle, _O_TEXT);
fp = _fdopen( hConHandle, "r" );
*stdin = *fp;
setvbuf( stdin, NULL, _IONBF, 0 );
// redirect unbuffered STDERR to the console
lStdHandle = GetStdHandle(STD_ERROR_HANDLE);
hConHandle = _open_osfhandle((intptr_t) lStdHandle, _O_TEXT);
fp = _fdopen( hConHandle, "w" );
*stderr = *fp;
setvbuf( stderr, NULL, _IONBF, 0 );
// make cout, wcout, cin, wcin, wcerr, cerr, wclog and clog 
// point to console as well
ios::sync_with_stdio();
}



My Python port:

from ctypes import windll, create_string_buffer,Structure, byref
from ctypes.wintypes import DWORD,SHORT, WORD
import os
import msvcrt
import sys

STD_INPUT_HANDLE  = -10
STD_OUTPUT_HANDLE = -11
STD_ERROR_HANDLE  = -12
INVALID_HANDLE_VALUE = DWORD(-1).value

MAX_LINES = 500

def consoleOptionEnabled(argv):
value = False
if ("--console" in argv) or ("-c" in argv):
value = True
return value

def redirectIOToConsole():
class CONSOLE_SCREEN_BUFFER_INFO(Structure):
_fields_ = [("dwSize", COORD),
("dwCursorPosition", COORD),
("wAttributes", WORD),
("srWindow", SMALL_RECT),
("dwMaximumWindowSize", DWORD)]

coninfo = CONSOLE_SCREEN_BUFFER_INFO()

# allocate console
if(windll.kernel32.GetStdHandle(STD_OUTPUT_HANDLE) != 
INVALID_HANDLE_VALUE):
windll.kernel32.AllocConsole()

# set the screen buffer to be big enough to let us scroll text

windll.kernel32.GetConsoleScreenBufferInfo(windll.kernel32.GetStdHandle(STD_OUTPUT_HANDLE),
 byref(coninfo))
coninfo.dwSize.Y = MAX_LINES

windll.kernel32.SetConsoleScreenBufferSize(windll.kernel32.GetStdHandle(STD_OUTPUT_HANDLE),
 coninfo.dwSize)

#redirect unbuffered STDOUT to the console
lStdHandle = windll.kernel32.GetStdHandle(STD_OUTPUT_HANDLE)

hConHandle = msvcrt.open_osfhandle(lStdHandle, os.O_TEXT)
fp = os.fdopen( hConHandle, "w" )
sys.stdout = fp
setvbuf( stdout, NULL, _IONBF, 0 )
# redirect unbuffered STDIN to the console
lStdHandle = windll.kernel32.GetStdHandle(STD_INPUT_HANDLE)
hConHandle = msvcrt.open_osfhandle(lStdHandle, os.O_TEXT)
fp = os.fdopen( hConHandle, "r" )
sys.stdin = fp
setvbuf( stdin, NULL, _IONBF, 0 )

#redirect unbuffered STDERR to the console
lStdHandle = windll.kernel32.GetStdHandle(STD_ERROR_HANDLE)
hConHandle = msvcrt.open_osfhandle(lStdHandle, os.O_TEXT)
fp = os.fdopen( hConHandle, "w" )
sys.stderr = fp
setvbuf( stderr, NULL, _IONBF, 0 )
# make cout, wcout, cin, wcin, wcerr, cerr, wclog and clog 
# point to console as well


Is there a better way to handling IO redirection to console in Python?

Thanks.

Austin
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: SystemError in python 2.5.4

2015-12-10 Thread Palpandi
On Thursday, December 10, 2015 at 5:08:05 PM UTC+5:30, Chris Angelico wrote:
> On Thu, Dec 10, 2015 at 10:29 PM, Palpandi  wrote:
> > Hi All,
> >
> > I am getting the error mentioned below in python 2.5.4.
> >
> > SystemError: \loewis\25\python\Objects\longobject.c:225: bad argument to 
> > internal function.
> >
> > I also ran the same code in python 2.7.
> > There I am not getting this error.
> >
> > I don't know which causes this error. Any solution for this?
> >
> > Note: The error is coming from the method call findall(path).
> >
> 
> Interesting! What platform (OS, etc) are you running this on? Python
> 2.5 isn't supported any more, so you might have to talk to Red Hat or
> someone. Alternatively, given that 2.7 doesn't have this problem, can
> you simply write it off as an issue with the older Python, and use 2.7
> instead?
> 
> ChrisA

ChrisA, Thanks for your quick response. 
I am using Windows and we are using 2.5.4 only.
Is there any workaround?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: SystemError in python 2.5.4

2015-12-10 Thread Chris Angelico
On Fri, Dec 11, 2015 at 12:14 AM, Palpandi  wrote:
> ChrisA, Thanks for your quick response.
> I am using Windows and we are using 2.5.4 only.
> Is there any workaround?

I wouldn't know. All I know is, upgrading to 2.7 gives you a lot of
other improvements too, so unless there's something serious holding
you back, move forward!

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Getting data out of Mozilla Thunderbird with Python?

2015-12-10 Thread Thomas 'PointedEars' Lahn
Michael Torrie wrote:

> It's good to know I can configure Thunderbird to use maildir for local
> storage.  I'll have to make the change here.  Will make my backups a lot
> easier and faster.

But see also .  Not all of 
those bugs have been resolved/fixed.

-- 
PointedEars

Twitter: @PointedEars2
Please do not cc me. / Bitte keine Kopien per E-Mail.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python variable assigning problems...

2015-12-10 Thread Denis McMahon
On Wed, 09 Dec 2015 09:49:26 -0800, ICT Ezy wrote:

> Pl refer question which attached image here:
> 
> link: https://drive.google.com/open?id=0B5L920jMv7T0dFNKQTJ2UUdudW8

I can't access the image with my G+ account because the image owner 
hasn't given me permission.

Perhaps you'd like to post a short self contained example of the problem 
here instead.

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: np.searchSorted over 2D array

2015-12-10 Thread Heli
Thanks Peter, 

I will try to explain what I really need. 

I have a 3D numpy array of 100*100*100 (1M elements). Then I have another numpy 
array of for example 10*2*10 (200 elements). I want to know if in the bigger 
dataset of 100*100*100, there is anywhere, where the second numpy array of 200 
elements with shape 10*2*10 appears. If it does, then I want the indices of the 
bigger dataset where this happens.

I hope I´m making myself more clear :)
Thanks for your comments,


On Wednesday, December 9, 2015 at 5:37:07 PM UTC+1, Peter Otten wrote:
> Heli wrote:
> 
> [Please don't open a new thread for the same problem] 
> 
> > I need to check whether two 2d numpy arrays have intersections and if so I
> > will need to have the cell indices of the intersection.
> > 
> > By intersection, I exactly mean the intersection definition used in set
> > theory.
> > 
> > I will give an example of what I need to do:
> > 
> > a=[[0,1,2],[3,4,5],[6,7,8]]
> > b=[[0,1,2],[3,4,5]]
> > 
> > I would like to check whether b is subset of a and then get the indices in
> > a where b matches.
> > 
> > cellindices=[[True,True,True],[True,True,True],[False,False,False]]
> > 
> > What is the best way to do this in numpy?
> 
> Providing an example is an improvement over your previous post, but to me 
> it's still not clear what you want.
> 
> >>> functools.reduce(lambda x, y: x | y, (a == i for i in b.flatten()))
> array([[ True,  True,  True],
>[ True,  True,  True],
>[False, False, False]], dtype=bool)
> 
> produces the desired result for the example input, but how do you want to 
> handle repeating numbers as in 
> 
> >>> a = numpy.array([[0,1,2],[3,4,5],[3, 2, 1]])
> >>> functools.reduce(lambda x, y: x | y, (a == i for i in b.flatten()))
> array([[ True,  True,  True],
>[ True,  True,  True],
>[ True,  True,  True]], dtype=bool)
> 
> ?
> 
> Try to be clear about your requirement, describe it in english and provide a 
> bit of context. You might even write a solution that doesn't use numpy and 
> ask for help in translating it.
> 
> At the very least we need more/better examples.
-- 
https://mail.python.org/mailman/listinfo/python-list


Administrators and moderators of Python-list, please erase all the messages that I not should have posted here in python-list!

2015-12-10 Thread françai s
Administrators and moderators of Python-list, please erase all the messages
that I  not should have posted here in python-list.

I ask this because I probably be in future a good programmer famous and I
do not want to talk about the topics that I should not have posted here in
python-list.

I decided prevent substantial harm to important relationships that probably
I will have in future with other developers.
-- 
https://mail.python.org/mailman/listinfo/python-list


python unit test frame work

2015-12-10 Thread Ganesh Pal
Hello Team,

Iam on python 2.7 and linux.  Iam trying to understand the python unit
test frame work and also trying to fix the below code , any help in
this regard would be appreciated ?

# Sample code starts here
inject_failure = {}
report = ""
ClassIsSetup = False
ClassCleanup = False

class Test_filesystem(unittest.TestCase):
  """ """
  def TestSetup(self):
""" Initial setup before unittests run  """
logging.info("SETUP.Started !!!")
if not os.path.ismount("/tmp"):  # Comment 1.
   logging.error("Error: /tmp is not mounted")
   sys.exit("/tmp is not mounted ...Exiting !!!")

if self.create_dataset() and capture_chksum():
   try:
   test01_log = os.path.join(LOG_DIR, "test01_corrupt.log")
   self.inject_failure['test01'] = tool.run_tool(test01_log)
   time.sleep(10)
   test02_log = os.path.join(LOG_DIR, "test01_corrupt.log")
   self.inject_failure['test01'] = tool.run_tool(test02_log)
   time.sleep(10)
   except Exception, e:
  logging.error(e)
  sys.exit(1)
if not run_scanner():
   sys.exit(1)
else:
 try:
 self.__class__.report = report_tool()
 except Exception, e:
logging.error(e)
sys.exit("Running Reporting tool failed")
logging.info("SETUP.Done !!!")

def setUp(self):
if not self.ClassIsSetup:
self.__class__.ClassIsSetup = True
self.setupClass()

def setupClass(self):
self.TestSetup()

def test_01_inode_test(self):
"""  test01: """
logging.info("### Executing test01: inode corruption ###")
self.assertTrue(run_db_tool(self.__class__.report,
   self.find_failure['test01']))
def test_02_hardlink_test(self):
"""  test02: """
logging.info("### Executing test01: inode corruption ###")
self.assertTrue(run_db_tool(self.__class__.report,

def tearDown(self):
if self.ClassCleanup:
self.tearDownClass()

def tearDownClass(self):
self.cleanup()

# Comment 2
def cleanup(self):
""" Cleanup all the data & logs """
logging.info("Cleaning all data")
os.system("rm -rf /tmp/data_set")

def main():
unittest.main()

if __name__ == '__main__':
  main()

# Sample code ends here

Questions :

1. If the setUp() fails the code still tries to run through the test
and  assert's with error.  How do I avoid these Error on the console ,
actually test01, test02, . etc , shouldn't run if the setup Failed ?

Example: If the  mount fails i.e  if not os.path.ismount("/tmp"): in
TestSetup(). we will get the below output:

#c_t.py

==
ERROR: test01: test_01_inode_test
--
Traceback (most recent call last):
  File "c_t.py", line xx, in setUp
self.setupClass()
  File "c_t.py", line xxx, in TestSetup
self.TestSetup()
  File "c_t.py", line xx, in corruptSetup
sys.exit("/tmp is not mounted ...Exiting !!!")
SystemExit: /tmp is not mounted ...Exiting !!!
==
ERROR: test02
--
Traceback (most recent call last):
  File "c_t.py", line 162, in  test_02_hardlink_test
self.inject_failures['test02']))
KeyError: 'test02'

Ran 2 tests in 0.003s
FAILED (errors=2)

2. The cleanup() never gets executed at the end of the test.
3. Any better idea or suggestions to improve the above code ?

Regards,
Ganesh
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Administrators and moderators of Python-list, please erase all the messages that I not should have posted here in python-list!

2015-12-10 Thread Nick Sarbicki
Great, now I have something I can use as blackmail when you are a rich and
famous programmer! /s

Joking aside, don't worry about embarrassing questions from your past.
We've all had a journey to being programmers and we've all done dumb things.

If anything, by trying to cover up your past you will do more to damage any
future relationships you will have with developers.

- Nick.

On Thu, Dec 10, 2015 at 2:55 PM françai s  wrote:

> Administrators and moderators of Python-list, please erase all the messages
> that I  not should have posted here in python-list.
>
> I ask this because I probably be in future a good programmer famous and I
> do not want to talk about the topics that I should not have posted here in
> python-list.
>
> I decided prevent substantial harm to important relationships that probably
> I will have in future with other developers.
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: python unit test frame work

2015-12-10 Thread Peter Otten
Ganesh Pal wrote:

> Hello Team,
> 
> Iam on python 2.7 and linux.  Iam trying to understand the python unit
> test frame work and also trying to fix the below code , any help in
> this regard would be appreciated ?

I recommend that you reread the unittest documentation. 

setUpClass() should be a class method, and if it succeeds you can release 
the ressources it required in the corresponding tearDownClass() method. As 
written the flags and the setUp()/tearDown() seem unnecessary.

If a necessary ressource cannot be acquired you can raise a SkipTest 
exception and the test or tests will not run.

> logging.info("### Executing test01: inode corruption ###")

In --verbose mode unittest will print the first line of the test methods' 
docstring. That should be sufficient most of the time.

Only loosely related:

Drop the habit to sprinkle sys.exit() all over the place. A well-behaved 
application has one exit point, at the end of the main module.

> self.__class__.report

When reading the report attribute this is the same as just

self.report

(unless you shaded it in the instance). 

> # Sample code starts here
> inject_failure = {}
> report = ""
> ClassIsSetup = False
> ClassCleanup = False
> 
> class Test_filesystem(unittest.TestCase):
>   """ """
>   def TestSetup(self):
> """ Initial setup before unittests run  """
> logging.info("SETUP.Started !!!")
> if not os.path.ismount("/tmp"):  # Comment 1.
>logging.error("Error: /tmp is not mounted")
>sys.exit("/tmp is not mounted ...Exiting !!!")
> 
> if self.create_dataset() and capture_chksum():
>try:
>test01_log = os.path.join(LOG_DIR, "test01_corrupt.log")
>self.inject_failure['test01'] = tool.run_tool(test01_log)
>time.sleep(10)
>test02_log = os.path.join(LOG_DIR, "test01_corrupt.log")
>self.inject_failure['test01'] = tool.run_tool(test02_log)
>time.sleep(10)
>except Exception, e:
>   logging.error(e)
>   sys.exit(1)
> if not run_scanner():
>sys.exit(1)
> else:
>  try:
>  self.__class__.report = report_tool()
>  except Exception, e:
> logging.error(e)
> sys.exit("Running Reporting tool failed")
> logging.info("SETUP.Done !!!")
> 
> def setUp(self):
> if not self.ClassIsSetup:
> self.__class__.ClassIsSetup = True
> self.setupClass()
> 
> def setupClass(self):
> self.TestSetup()
> 
> def test_01_inode_test(self):
> """  test01: """
> logging.info("### Executing test01: inode corruption ###")
> self.assertTrue(run_db_tool(self.__class__.report,
>
self.find_failure['test01']))
> def test_02_hardlink_test(self):
> """  test02: """
> logging.info("### Executing test01: inode corruption ###")
> self.assertTrue(run_db_tool(self.__class__.report,
> 
> def tearDown(self):
> if self.ClassCleanup:
> self.tearDownClass()
> 
> def tearDownClass(self):
> self.cleanup()
> 
> # Comment 2
> def cleanup(self):
> """ Cleanup all the data & logs """
> logging.info("Cleaning all data")
> os.system("rm -rf /tmp/data_set")
> 
> def main():
> unittest.main()
> 
> if __name__ == '__main__':
>   main()
> 
> # Sample code ends here
> 
> Questions :
> 
> 1. If the setUp() fails the code still tries to run through the test
> and  assert's with error.  How do I avoid these Error on the console ,
> actually test01, test02, . etc , shouldn't run if the setup Failed ?
> 
> Example: If the  mount fails i.e  if not os.path.ismount("/tmp"): in
> TestSetup(). we will get the below output:
> 
> #c_t.py
> 
> ==
> ERROR: test01: test_01_inode_test
> --
> Traceback (most recent call last):
>   File "c_t.py", line xx, in setUp
> self.setupClass()
>   File "c_t.py", line xxx, in TestSetup
> self.TestSetup()
>   File "c_t.py", line xx, in corruptSetup
> sys.exit("/tmp is not mounted ...Exiting !!!")
> SystemExit: /tmp is not mounted ...Exiting !!!
> ==
> ERROR: test02
> --
> Traceback (most recent call last):
>   File "c_t.py", line 162, in  test_02_hardlink_test
> self.inject_failures['test02']))
> KeyError: 'test02'
> 
> Ran 2 tests in 0.003s
> FAILED (errors=2)
> 
> 2. The cleanup() never gets executed at the end of the test.
> 3. Any better idea or suggestions to improve the above code ?
> 
> Regards,
> Ganesh


-- 
https://mail.python.org/mail

Re: non-blocking getkey?

2015-12-10 Thread Ulli Horlacher
Ulli Horlacher  wrote:

> My idea now is: instead of raw_input() I use a get_paste() function, which
> reads input character for input character and after a (say) 1 s timeout it
> returns the string. Pasting a string with the mouse is rather fast, there
> should be no big delay between the characters.
> 
> How can I implement such a get_paste() function?
> I need a non-blocking getkey() function.

I found a solution for Windows:

  print("\nCopy&paste a filename or drag&drop a file into this window")
  file = get_paste()
  print('\n"%s"' % file)


def get_paste():
  import msvcrt
  c = msvcrt.getch()
  if c == '\n' or c == '\r': return ''
  paste = c
  while msvcrt.kbhit():
c = msvcrt.getch()
if c == '\n' or c == '\r': break
paste += c
  return paste

-- 
Ullrich Horlacher  Server und Virtualisierung
Rechenzentrum IZUS/TIK E-Mail: horlac...@tik.uni-stuttgart.de
Universitaet Stuttgart Tel:++49-711-68565868
Allmandring 30aFax:++49-711-682357
70550 Stuttgart (Germany)  WWW:http://www.tik.uni-stuttgart.de/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Administrators and moderators of Python-list, please erase all the messages that I not should have posted here in python-list!

2015-12-10 Thread Michael Torrie
On 12/10/2015 07:44 AM, françai s wrote:
> Administrators and moderators of Python-list, please erase all the messages
> that I  not should have posted here in python-list.
> 
> I ask this because I probably be in future a good programmer famous and I
> do not want to talk about the topics that I should not have posted here in
> python-list.
> 
> I decided prevent substantial harm to important relationships that probably
> I will have in future with other developers.

While the folks who run the python.org archive do try to respond to
people's requests for removal, particularly in the case of libelous and
abusive messages, be aware that this list is also connected with the
large, decentralize usenet message system, and also is archived by
numerous newsgroup archiving web sites, and removal from the archive
hosted at python.org will not remove messages in those other places.

What could you have possibly said that would cause substantial harm to
future relationships?  Also, how are the web masters supposed to know
what you shouldn't have posted and what was okay?

I have read this mailing list for years now, and I don't recall having
seen anything from your email address that would be cause for concern.
I'm sure potential employers and colleagues can understand that you once
didn't know as much about Python and programming, and that you've
learned and become a better programmer over the years.

In short, I wouldn't worry about this at all if I were you (unless you
are PointedEars, RR, or our resident unicode troll). I'd worry far more
about social networks than the python mailing list.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Administrators and moderators of Python-list, please erase all the messages that I not should have posted here in python-list!

2015-12-10 Thread Michael Torrie
On 12/10/2015 07:44 AM, françai s wrote:
> Administrators and moderators of Python-list, please erase all the messages
> that I  not should have posted here in python-list.
> 
> I ask this because I probably be in future a good programmer famous and I
> do not want to talk about the topics that I should not have posted here in
> python-list.
> 
> I decided prevent substantial harm to important relationships that probably
> I will have in future with other developers.

Just FYI again here, when I search for your email address on google, the
first few entries are your posts to several other mailing lists and
usenet groups making this same request.  I'd say that that honestly
looks far worse, from an internet search pov, than anything you might
have said on the mailing lists in a technical vein.  Good luck.

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


testfixtures 4.7.0 Released!

2015-12-10 Thread Chris Withers

Hi All,

I'm pleased to announce the release of testfixtures 4.7.0. Since 4.5.1, 
the following have been added:


- Add the ability to pass raises=False to compare() to just get
  the resulting message back rather than having an exception raised.

- Fix a bug that mean symlinked directories would never show up when
  using TempDirectory.compare() and friends.

- Add the `followlinks` parameter to TempDirectory.compare() to
  indicate that symlinked or hard linked directories should be recursed
  into when using `recursive=True`.

The package is on PyPI and a full list of all the links to docs, issue 
trackers and the like can be found here:


https://github.com/Simplistix/testfixtures

Any questions, please do ask on the Testing in Python list or on the 
Simplistix open source mailing list...


cheers,

Chris

--
Simplistix - Content Management, Batch Processing & Python Consulting
   - http://www.simplistix.co.uk
--
https://mail.python.org/mailman/listinfo/python-list


Re: np.searchSorted over 2D array

2015-12-10 Thread Oscar Benjamin
On 10 Dec 2015 14:46, "Heli"  wrote:
>
> Thanks Peter,
>
> I will try to explain what I really need.
>
> I have a 3D numpy array of 100*100*100 (1M elements). Then I have another
numpy array of for example 10*2*10 (200 elements). I want to know if in the
bigger dataset of 100*100*100, there is anywhere, where the second numpy
array of 200 elements with shape 10*2*10 appears. If it does, then I want
the indices of the bigger dataset where this happens.
>

So you want to find N in M. First find all occurrences of N[0][0][0] in
M[:90][:98][:90]. Then for each of those extract the same size subview from
M and check if (Ms == N).all().

--
Oscar
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: python unit test frame work

2015-12-10 Thread Ganesh Pal
+python list .  sorry I accidentally did a reply to Peter.

On Dec 11, 2015 3:57 AM, "Ganesh Pal"  wrote:
>
>
> > Drop the habit to sprinkle sys.exit() all over the place. A well-behaved
> > application has one exit point, at the end of the main module.
>
I was using sys.exit() as the means to stop the  execution or terminate the
program. I can't think of an alternative for my case :
I have multiple checks if I don't meet them continuing with the main
program doesn't make sense

Regards,
Ganesh
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: python unit test frame work

2015-12-10 Thread Ben Finney
Ganesh Pal  writes:

> I have multiple checks if I don't meet them continuing with the main
> program doesn't make sense

That means these are not unit tests (which are isolatable, independent
test cases).

If the tests are best characterised as a sequence of steps, then the
‘unittest’ model (designed for actual unit tests) will not fit well.

You should instead just write a ‘main’ function that calls each test
case in turn and exits when one of them fails.

import sys

from .. import foo_app


def test_input_wibble_returns_lorem(frob):
""" Should process 'wibble' input and result in state 'lorem'. """
frob.process("wibble")
if frob.state != "lorem":
raise AssertionError


def test_input_warble_returns_ipsum():
""" Should process warble' input and result in state 'ipsum'. """
frob.process("warble")
if frob.state != "ipsum":
raise AssertionError


# …

EXIT_STATUS_ERROR = 1

def main(argv):
""" Mainline code for this module. """

process_args(argv)

test_cases = [
test_input_wibble_returns_lorem,
test_input_warble_returns_ipsum,
# …
]

test_frob = foo_app.Frob()

for test_case in test_cases:
try:
test_case(test_frob)
except AssertionError as exc:
sys.stderr.write("Test run failed ({exc})".format(exc=exc))
sys.exit(EXIT_STATUS_ERROR)


if __name__ == "__main__":
exit_status = main(sys.argv)
sys.exit(exit_status)

-- 
 \“The greatest tragedy in mankind's entire history may be the |
  `\   hijacking of morality by religion.” —Arthur C. Clarke, 1991 |
_o__)  |
Ben Finney

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


Re: python unit test frame work

2015-12-10 Thread Cameron Simpson

On 11Dec2015 04:05, Ganesh Pal  wrote:

On Dec 11, 2015 3:57 AM, "Ganesh Pal"  wrote:

> Drop the habit to sprinkle sys.exit() all over the place. A well-behaved
> application has one exit point, at the end of the main module.


I was using sys.exit() as the means to stop the  execution or terminate the
program. I can't think of an alternative for my case :
I have multiple checks if I don't meet them continuing with the main
program doesn't make sense


First, as Ben remarks, if one test _depends_ on an earlier one then it isn't a 
real unit test.


On the other hand, if you simply have some simple tests followed by more 
complex tests (I have several like this) you have two facilities to help you.  

Firstly, I have observed that unittest tends to run tests in lexical order, so 
I tend to name the test methods like this:


 def test00minimalist(self):
 def test01minimalPlusOneThing(self):
 ...
 def test20somethingComplex(self):

and on the command line when you are hand testing things:

 python -m cs.venti.tcp_tests -v -f

Of course, substitute your module name. The -v recites the test names and 
docstring first line as Peter has mentioned. The -f causes the etst suit to 
fail on the first test failure, and does not run the later tests. That seems to 
cover what you want here: abort on the simplest failing test.


Cheers,
Cameron Simpson 
--
https://mail.python.org/mailman/listinfo/python-list


Re: How to use internal python c funtions, from python code

2015-12-10 Thread srinivas devaki
Thank you Chris,
later I  decided that this would be cheating  and I have to think about
another algorithmic approach.

most of the competitive programming platforms provide python with a time
limit of 5 times of c/c++ time limit. but in many cases like if the
algorithms are recursive(like segment trees etc) that 5 factor is just not
enough.

but still I think it would be cool to be able to access internal c
functions without any fuss. I can use such feature with heapq too(sift
operations),
-- 
https://mail.python.org/mailman/listinfo/python-list


real usable file/directory operation module?

2015-12-10 Thread oyster
there is shutil module, but I find it limits the user heavily. For
example, I want to move 2 directories "a/scene" and "c/scene" to "d",
but there is "scene" under d already. Then shutil.move will raise
Error, "Destination path '%s' already exists" % real_dst

So is there any module, which allow me move/copy like Windows does.
for example
useableShutil.move('a/scene', 'd', overwite=True)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: python unit test frame work

2015-12-10 Thread Ben Finney
Cameron Simpson  writes:

> First, as Ben remarks, if one test _depends_ on an earlier one then it
> isn't a real unit test.
>
> On the other hand, if you simply have some simple tests followed by
> more complex tests (I have several like this) you have two facilities
> to help you.
>
> Firstly, I have observed that unittest tends to run tests in lexical
> order

Back on the first hand again, some unit test runners will deliberately
*change* the order so your test cases are tested for independence.

Really, if your test cases depend on being executed in a particular
sequence, the ‘unittest’ module is a poor fit.

-- 
 \   “Come on, if your religion is so vulnerable that a little bit |
  `\   of disrespect is going to bring it down, it's not worth |
_o__)   believing in, frankly.” —Terry Gilliam, 2005-01-18 |
Ben Finney

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


Re: real usable file/directory operation module?

2015-12-10 Thread Cameron Simpson

On 11Dec2015 11:04, oyster  wrote:

there is shutil module, but I find it limits the user heavily. For
example, I want to move 2 directories "a/scene" and "c/scene" to "d",
but there is "scene" under d already. Then shutil.move will raise
Error, "Destination path '%s' already exists" % real_dst

So is there any module, which allow me move/copy like Windows does.
for example
useableShutil.move('a/scene', 'd', overwite=True)


Surely the "subprocess" module, which would let you invoke the Windows copy 
command.


The reason that the stdlib doesn't offer something like that is that there are 
many many decisions one might make when overlaying one directory tree on 
another. Consult the manual entry for rsync to get a feel for how many nuances 
one might want in such a situation. The Window's "copy" command makes one set 
of choices; they may not fit many users' needs.


Instead the stdlib supports the simple "no conflicts" case (which is safe) and 
leaves it to others to solve harder problems, because there are many ways to 
"solve" those problems.


It is very easy to invoke os.walk on the "copying in" tree and compute the 
matching paths in the target directory, and then make your own decisions (make 
missing intermediate directories, overwrite existing files or only if the 
source is newer or whatever). BTW, if you go this route (write your own) then I 
suggest you give it a "no action" mode to report what it will do - that way you 
can check first before destroying your data.


Cheers,
Cameron Simpson 
--
https://mail.python.org/mailman/listinfo/python-list


Re: python unit test frame work

2015-12-10 Thread Cameron Simpson

On 11Dec2015 14:09, Ben Finney  wrote:

Cameron Simpson  writes:

First, as Ben remarks, if one test _depends_ on an earlier one then it
isn't a real unit test.

On the other hand, if you simply have some simple tests followed by
more complex tests (I have several like this) you have two facilities
to help you.

Firstly, I have observed that unittest tends to run tests in lexical
order


Back on the first hand again, some unit test runners will deliberately
*change* the order so your test cases are tested for independence.


That's fine. My tests are independent. But it is _handy_ that while building 
the tests and adding new tests that they are issued in a predictable order.



Really, if your test cases depend on being executed in a particular
sequence, the ‘unittest’ module is a poor fit.


Yes, but that is not the case for me, and quite possibly for the OP. Even if 
they aren't, he seems savvy and quick to learn and willing to adjust worse 
practice for better.


Cheers,
Cameron Simpson 
--
https://mail.python.org/mailman/listinfo/python-list