-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathabout_none.py
51 lines (37 loc) · 1.48 KB
/
about_none.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Based on AboutNil in the Ruby Koans
#
from runner.koan import *
class AboutNone(Koan):
def test_none_is_an_object(self):
"Unlike NULL in a lot of languages"
self.assertEqual(__, isinstance(None, object))
def test_none_is_universal(self):
"There is only one None"
self.assertEqual(____, None is None)
def test_what_exception_do_you_get_when_calling_nonexistent_methods_on_None(self):
"""
What is the Exception that is thrown when you call a method that does
not exist?
Hint: launch python command console and try the code in the block below.
Don't worry about what 'try' and 'except' do, we'll talk about this later
"""
# Don't forget to unindent before you try to run this code block:
try:
None.some_method_none_does_not_know_about()
except Exception as ex:
ex2 = ex
ex2
# What exception has been caught?
self.assertEqual(__, ex2.__class__.__name__)
# What message was attached to the exception?
# (HINT: replace __ with part of the error message.)
self.assertRegexpMatches(ex2.args[0], __)
def test_none_is_distinct(self):
"""
None is distinct from other things which are False.
"""
self.assertEqual(__, None is not 0)
self.assertEqual(__, None is not False)