Skip to content

Commit

Permalink
added test 1, changed test2=test1 test3=test2 test1=new test
Browse files Browse the repository at this point in the history
  • Loading branch information
KerbezOrazgaliyeva committed Dec 9, 2018
1 parent 891a623 commit cdb42cc
Show file tree
Hide file tree
Showing 18 changed files with 191 additions and 159 deletions.
77 changes: 0 additions & 77 deletions context_manager/answers/context_manager.py

This file was deleted.

17 changes: 17 additions & 0 deletions context_manager/answers/context_manager_as_class.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class File(object):
def __init__(self, file_name, method):
self.file_obj = open(file_name, method)
def __enter__(self):
return self.file_obj
def __exit__(self, type, value, traceback):
self.file_obj.close()

def check(filename):
with File(filename, 'w') as opened_file:
opened_file.write('Yeah! You can write context manager as class)')


def read_file(filename):
with open(filename, 'r') as f:
for line in f:
return format(line)
16 changes: 16 additions & 0 deletions context_manager/context_manager_as_class.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
class File(object):
"""
Context manager class with '__init__', '__enter__', '__exit__' methods that opens and closes file.
"""

def check(filename):
"""
Writes 'Yeah! You can write context manager as class)') into filename with File class.
:param filename: txt file
"""


def read_file(filename):
with open(filename, 'r') as f:
for line in f:
return format(line)
Empty file removed context_manager/first.txt
Empty file.
23 changes: 11 additions & 12 deletions context_manager/instruction.md
Original file line number Diff line number Diff line change
@@ -1,42 +1,42 @@
### LEVEL-1.

1. Look at the file write_into_file.py
1. Look at the file context_manager_as_class.py

2. Look at the tests in tests folder
2. Look at the test_context_manager_as_class.py in tests folder

3. Run tests with command:

```python3 -m unittest tests/test_write_into_file.py```
```python3 -m unittest tests/test_context_manager_as_class.py```

As you see all your tests are failed

4. Now, complete the functions in write_into_file.py
4. Now, complete the functions in context_manager_as_class.py

5. Run tests and all of them should be passed.

6. Compare your answer with mine located in answers/write_into_file.py
6. Compare your answer with mine located in answers/change_directory.py

7. Congratulations, you have passed first level. Commit and push your changes.

### LEVEL-2

1. Look at the file change_directory.py
1. Look at the file write_into_file.py

2. Look at the test_change_directory.py in tests folder
2. Look at the tests in tests folder

3. Run tests with command:

```python3 -m unittest tests/test_change_directory.py```
```python3 -m unittest tests/test_write_into_file.py```

As you see all your tests are failed

4. Now, complete the functions in change_directory.py
4. Now, complete the functions in write_into_file.py

5. Run tests and all of them should be passed.

6. Compare your answer with mine located in answers/change_directory.py
6. Compare your answer with mine located in answers/write_into_file.py

7. Congratulations, you have passed second level. Commit and push your changes.
7. Congratulations, you have passed first level. Commit and push your changes.

### LEVEL-3

Expand All @@ -58,4 +58,3 @@

7. Congratulations, you have passed second level. Commit and push your changes.


Empty file removed context_manager/second.txt
Empty file.
49 changes: 0 additions & 49 deletions context_manager/tests/context_manager_test.py

This file was deleted.

11 changes: 11 additions & 0 deletions context_manager/tests/test_context_manager_as_class.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from unittest import TestCase
from context_manager_as_class import (
check,
read_file
)

class LevelOneTest(TestCase):
def test_write_with1(self):
check('first.txt')
result = read_file('first.txt')
self.assertEqual(result, 'Yeah! You can write context manager as class)')
2 changes: 1 addition & 1 deletion context_manager/tests/test_write_into_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
read_file
)

class LevelOneTest(TestCase):
class LevelTwoTest(TestCase):
def test_write_without(self):
result = write_without_context_manager('first.txt')
self.assertEqual(result, True)
Expand Down
Empty file removed context_manager/third.txt
Empty file.
Binary file modified docs/build/doctrees/context_manager.doctree
Binary file not shown.
Binary file modified docs/build/doctrees/environment.pickle
Binary file not shown.
Binary file modified docs/build/doctrees/index.doctree
Binary file not shown.
45 changes: 40 additions & 5 deletions docs/build/html/_sources/context_manager.rst.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,37 @@ or as class by using magic functions::

We want you to pass three levels for a better understanding of **context manager**

Context manager as class
------------------------

1. Look at the file context_manager_as_class.py

LEVEL-1
-------
2. Look at the test_context_manager_as_class.py in tests folder

3. Run tests with command::

python3 -m unittest tests/test_context_manager_as_class.py

As you see all your tests are failed

4. Now, complete the functions in context_manager_as_class.py

5. Run tests and all of them should be passed.

6. Compare your answer with mine located in answers/change_directory.py

7. Congratulations, you have passed first level. Commit and push your changes.

Write into file
---------------

1. Look at the file write_into_file.py

2. Look at the tests in tests folter

3. Run tests with command::

python3 -m unittest tests/tests_for_level_one.py
python3 -m unittest tests/tests_write_into_file.py

As you see all your tests are failed

Expand All @@ -47,6 +66,22 @@ LEVEL-1

7. Congratulations, you have passed first level. Commit and push your changes.

LEVEL-2
-------
Change directory
----------------
1. Look at the file change_directory.py

2. Look at the test_change_directory.py in tests folder

3. Run tests with command::

python3 -m unittest tests/test_change_directory.py

As you see all your tests are failed

4. Now, complete the functions in change_directory.py

5. Run tests and all of them should be passed.

6. Compare your answer with mine located in answers/change_directory.py

7. Congratulations, you have passed second level. Commit and push your changes.
58 changes: 51 additions & 7 deletions docs/build/html/context_manager.html
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,9 @@
<li class="toctree-l1"><a class="reference internal" href="fibonacci_numbers.html">Fibonacci numbers</a></li>
<li class="toctree-l1"><a class="reference internal" href="decorators.html">Decorators</a></li>
<li class="toctree-l1 current"><a class="current reference internal" href="#">Context manager</a><ul>
<li class="toctree-l2"><a class="reference internal" href="#level-1">LEVEL-1</a></li>
<li class="toctree-l2"><a class="reference internal" href="#level-2">LEVEL-2</a></li>
<li class="toctree-l2"><a class="reference internal" href="#context-manager-as-class">Context manager as class</a></li>
<li class="toctree-l2"><a class="reference internal" href="#write-into-file">Write into file</a></li>
<li class="toctree-l2"><a class="reference internal" href="#change-directory">Change directory</a></li>
</ul>
</li>
</ul>
Expand Down Expand Up @@ -171,15 +172,38 @@ <h1>Context manager<a class="headerlink" href="#context-manager" title="Permalin
</pre></div>
</div>
<p>We want you to pass three levels for a better understanding of <strong>context manager</strong></p>
<div class="section" id="level-1">
<h2>LEVEL-1<a class="headerlink" href="#level-1" title="Permalink to this headline"></a></h2>
<div class="section" id="context-manager-as-class">
<h2>Context manager as class<a class="headerlink" href="#context-manager-as-class" title="Permalink to this headline"></a></h2>
<ol class="arabic">
<li><p class="first">Look at the file context_manager_as_class.py</p>
</li>
<li><p class="first">Look at the test_context_manager_as_class.py in tests folder</p>
</li>
<li><p class="first">Run tests with command:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">python3</span> <span class="o">-</span><span class="n">m</span> <span class="n">unittest</span> <span class="n">tests</span><span class="o">/</span><span class="n">test_context_manager_as_class</span><span class="o">.</span><span class="n">py</span>
</pre></div>
</div>
<p>As you see all your tests are failed</p>
</li>
<li><p class="first">Now, complete the functions in context_manager_as_class.py</p>
</li>
<li><p class="first">Run tests and all of them should be passed.</p>
</li>
<li><p class="first">Compare your answer with mine located in answers/change_directory.py</p>
</li>
<li><p class="first">Congratulations, you have passed first level. Commit and push your changes.</p>
</li>
</ol>
</div>
<div class="section" id="write-into-file">
<h2>Write into file<a class="headerlink" href="#write-into-file" title="Permalink to this headline"></a></h2>
<ol class="arabic">
<li><p class="first">Look at the file write_into_file.py</p>
</li>
<li><p class="first">Look at the tests in tests folter</p>
</li>
<li><p class="first">Run tests with command:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">python3</span> <span class="o">-</span><span class="n">m</span> <span class="n">unittest</span> <span class="n">tests</span><span class="o">/</span><span class="n">tests_for_level_one</span><span class="o">.</span><span class="n">py</span>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">python3</span> <span class="o">-</span><span class="n">m</span> <span class="n">unittest</span> <span class="n">tests</span><span class="o">/</span><span class="n">tests_write_into_file</span><span class="o">.</span><span class="n">py</span>
</pre></div>
</div>
<p>As you see all your tests are failed</p>
Expand All @@ -194,8 +218,28 @@ <h2>LEVEL-1<a class="headerlink" href="#level-1" title="Permalink to this headli
</li>
</ol>
</div>
<div class="section" id="level-2">
<h2>LEVEL-2<a class="headerlink" href="#level-2" title="Permalink to this headline"></a></h2>
<div class="section" id="change-directory">
<h2>Change directory<a class="headerlink" href="#change-directory" title="Permalink to this headline"></a></h2>
<ol class="arabic">
<li><p class="first">Look at the file change_directory.py</p>
</li>
<li><p class="first">Look at the test_change_directory.py in tests folder</p>
</li>
<li><p class="first">Run tests with command:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">python3</span> <span class="o">-</span><span class="n">m</span> <span class="n">unittest</span> <span class="n">tests</span><span class="o">/</span><span class="n">test_change_directory</span><span class="o">.</span><span class="n">py</span>
</pre></div>
</div>
<p>As you see all your tests are failed</p>
</li>
<li><p class="first">Now, complete the functions in change_directory.py</p>
</li>
<li><p class="first">Run tests and all of them should be passed.</p>
</li>
<li><p class="first">Compare your answer with mine located in answers/change_directory.py</p>
</li>
<li><p class="first">Congratulations, you have passed second level. Commit and push your changes.</p>
</li>
</ol>
</div>
</div>

Expand Down
Loading

0 comments on commit cdb42cc

Please sign in to comment.