[Tutor] Does the secrets module in Python 3.6 use a hardware RNG like that provided in Intel CPUs?

2018-03-09 Thread Simon Connah via Tutor
Hi,
I was reading through the secrets documentation in Python 3.6 and noticed that 
it uses /dev/urandom but I'm unsure if that means it'll use a hardware RNG or 
just one provided by the operating system (Linux / Windows / etc) in software. 
The question is is it possible to determine the source of the randomness from 
os.urandom if there was ever a flaw found in a particular hardware RNG? Plus 
systems could have a third party hardware RNG that was an external addon card 
or similar which might be better than the one found in Intel CPUs.
I'm just a bit curious about the whole "will always use the strongest source 
for pseudo-random numbers" when research could change that assumption overnight 
based on discovered flaws.
This is probably a really stupid question and if it is I apologise but I'm 
somewhat confused.
Thanks for any help.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Proper way to unit test the raising of exceptions?

2018-04-01 Thread Simon Connah via Tutor
Hi,
I'm just wondering what the accepted way to handle unit testing exceptions is? 
I know you are meant to use assertRaises, but my code seems a little off.
try:    some_func()
except SomeException:    self.assertRaises(SomeException)
Is there a better way to do this at all? The problem with the above code is 
that if no exception is raised the code completely skips the except block and 
that would mean that the unit test would pass so, I considered adding:
self.fail('No exception raised')
at the end outside of the except block but not sure if that is what I need to 
do.
Any help is appreciated.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Proper way to unit test the raising of exceptions?

2018-04-01 Thread Simon Connah via Tutor
 Awesome. Thank you all. Your solutions are great and should make the whole 
process a lot more simple.
The only problem is that some_func() on my end is Django model with about 8 
named arguments so it might be a bit of a pain passing all of those arguments.
The context manager example seems like a perfect fit for that particular 
problem.
Thanks again. All of your help is much appreciated.
On Sunday, 1 April 2018, 16:32:11 BST, Mats Wichmann  
wrote:  
 
 On 04/01/2018 09:10 AM, Peter Otten wrote:
> Simon Connah via Tutor wrote:
> 
>> Hi,
>> I'm just wondering what the accepted way to handle unit testing exceptions
>> is? I know you are meant to use assertRaises, but my code seems a little
>> off. 
> 
>> try:
>>    some_func()
>> except SomeException:  
>>    self.assertRaises(SomeException) 
> 
> The logic is wrong here as you surmise below. If you catch the exception 
> explicitly you have to write
> 
> try:
>    some_func()
> except SomeException:
>    pass  # OK
> else:
>    self.fail("no exception raised")


If you use PyTest, the procedure is pretty well documented:

https://docs.pytest.org/en/latest/assert.html

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
  
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor