Пример #1
0
    def test_load_reads_file_as_json(self):
        load('file.json')

        open_context_mock = self.open_mock.return_value \
            .__enter__.return_value

        self.json_mock.load.assert_called_once_with(open_context_mock)
Пример #2
0
def load_all():
    return files.load('data/parts.json')
Пример #3
0
    def test_load_returns_empty_list_when_file_not_found(self):
        self.open_mock.side_effect = FileNotFoundError

        result = load('file.json')

        self.assertEqual([], result)
Пример #4
0
    def test_load_returns_loaded_json(self):
        self.json_mock.load.return_value = [{'name': 2}]

        result = load('file.json')

        self.assertEqual([{'name': 2}], result)
Пример #5
0
    def test_load_sets_read_permissions_for_open(self):
        load('file.json')

        self.open_mock.assert_called_once_with(ANY, 'r')
Пример #6
0
    def test_load_sets_path_to_file(self):
        load('file.json')

        self.open_mock.assert_called_once_with('file.json', ANY)