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
#include <stdio.h> | |
#include <unistd.h> | |
#include <stdlib.h> | |
#include <signal.h> | |
int sum; | |
int calculate(int first, int second) { | |
sum = first + second; | |
sleep(3); // represent I/O intensive function call |
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
#include <stdio.h> | |
#include <unistd.h> | |
int sum; | |
int calculate(int first, int second) { | |
sum = first + second; | |
sleep(3); // represent I/O intensive function call | |
return sum; | |
} |
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
use nix::sys::signal::*; | |
use nix::sys::signal::SigAction; | |
use std::time::Duration; | |
use std::thread; | |
fn calculate(first: i32, second: i32) -> i32 { | |
let sum = first + second; | |
thread::sleep(Duration::from_secs(3)); | |
sum | |
} |
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
use std::thread; | |
use std::time::Duration; | |
static mut SUM: i32 = 0; | |
fn calculate(first: i32, second: i32) -> i32 { | |
unsafe { | |
SUM = first + second; | |
} | |
thread::sleep(Duration::from_secs(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
#include <netdb.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#include <sys/socket.h> | |
#include <netinet/in.h> | |
#include <arpa/inet.h> | |
#include <unistd.h> | |
int main(int argc, char const *argv[]) |
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
@patch.object( | |
UserController, "__init__", Mock(return_value=None) | |
) | |
def test_get_second_picture(self): | |
mock_app = MagicMock() | |
mock_app.get_DB.return_value.all.return_value = ["Test 1", "Test 2"] | |
user = UserController() | |
user.picture = mock_app |
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
@patch.object( | |
UserController, "__init__", Mock(return_value=None) | |
) | |
def test_get_second_picture(self): | |
mock_app = MagicMock() | |
mock_app.get_DB.all.return_value = ["Test 1", "Test 2"] | |
user = UserController() | |
user.picture = mock_app |
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
class FakeDBAL: | |
def all(self): | |
print("all() method called") | |
return ["Pic1", "Pic2", "Pic3"] | |
class Picture: | |
def __init__(self): | |
print("__init__ method in the Picture class called") | |
self.dbal = FakeDBAL() |
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
@patch.object( | |
UserController, "__init__", Mock(return_value=None) | |
) | |
def test_get_first_picture(self): | |
mock_app = MagicMock() | |
mock_app.dbal.all.return_value = ["Test 1", "Test 2"] | |
user = UserController() | |
user.picture = mock_app |
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
@patch.object( | |
UserController, "__init__", Mock(return_value=None) | |
) | |
def test_get_first_picture(self): | |
user = UserController() | |
user.picture = MagicMock() | |
self.assertEqual("Test 1", user.get_first_picture()) |