This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def add(num1, num2): | |
return num1 + num2 | |
def subtract(num1, num2): | |
return num1 - num2 | |
def multiply(num1, num2): | |
return num1 * num2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import unittest | |
import simple_calc as sc | |
class SimpleCalcTest(unittest.TestCase): | |
def test_add(self): | |
result = sc.add(1, 2) | |
self.assertEqual(result, 3) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import file_utils | |
file_path = "INSERT_PATH_HERE" | |
def get_users(): | |
users = file_utils.read_file(file_path) | |
return users | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def write_file(path, content): | |
file_to_write = open(path, "w") | |
file_to_write.write(content) | |
file_to_write.close() | |
def read_file(path): | |
with open(path, 'r') as file_to_read: | |
data = file_to_read.read() | |
return data |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import unittest | |
import mock | |
import users | |
import file_utils | |
class UsersTest(unittest.TestCase): | |
_file_path = "SOME FILE PATH" | |
def test_get_users(self): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import unittest | |
import mock | |
import users | |
import file_utils | |
class UsersTest(unittest.TestCase): | |
_file_path = "INSERT_PATH_HERE" | |
def test_get_users(self): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import unittest | |
import mock | |
import users | |
import file_utils | |
class UsersTest(unittest.TestCase): | |
_file_path = "INSERT_PATH_HERE" | |
def test_get_users(self): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import unittest | |
import mock | |
import users | |
import file_utils | |
class UsersTest(unittest.TestCase): | |
_file_path = "INSERT_PATH_HERE" | |
@mock.patch("file_utils.read_file", return_value="user1") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import unittest | |
import mock | |
import file_utils | |
class FileUtilsTest(unittest.TestCase): | |
def test_read_file(self): | |
with mock.patch("__builtin__.open", mock.mock_open(read_data="MOCKED"), create=True) as mock_file: | |
result = file_utils.read_file("path") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def find_user(username): | |
if username == "user1": | |
return dict(name="user1", id_no="12345") | |
else: | |
raise Exception | |
def does_user_exist(username): | |
try: | |
find_user(username) |
OlderNewer