Example #1
0
    def test_get_idempotent(self):
        file_store = File(TEST_FILE_PATH)
        result = file_store.get()

        self.assertEqual(result, TEST_FILE_DICT)
        self.assertIsInstance(result, dict)

        result = file_store.get()

        self.assertEqual(result, TEST_FILE_DICT)
        self.assertIsInstance(result, dict)
        builtins.open.assert_called_once_with(TEST_FILE_PATH, "r")
Example #2
0
    def test_get_idempotent(self):
        file_store = File(TEST_FILE_PATH)
        result = file_store.get()

        self.assertEqual(result, TEST_FILE_DICT)
        self.assertIsInstance(result, dict)

        result = file_store.get()

        self.assertEqual(result, TEST_FILE_DICT)
        self.assertIsInstance(result, dict)
        if version_info.major < 3:
            __builtin__.open.assert_called_once_with(TEST_FILE_PATH, "r")
        else:
            builtins.open.assert_called_once_with(TEST_FILE_PATH, "r")
Example #3
0
    def test_open_nonexistent_file_returns_empty_dict(self, mock_open):
        simplefilter("ignore")
        file_store = File(TEST_FILE_PATH)
        result = file_store.get()

        self.assertEqual(result, {})
        self.assertIsInstance(result, dict)
Example #4
0
    def test_custom_encoding_without_parser_returns_empty_dict(
            self, mock_open):
        file_store = File(TEST_FILE_PATH, encoding='foo')
        result = file_store.get()

        self.assertEqual(result, {})
        self.assertIsInstance(result, dict)
Example #5
0
    def test_get_custom_encoding(self):
        mock_parser = MagicMock()
        mock_parser.return_value = TEST_FILE_DICT
        file_store = File(TEST_FILE_PATH,
                          encoding="custom",
                          parser=mock_parser)
        result = file_store.get()

        mock_parser.assert_called_once_with(TEST_FILE_RAW)
        self.assertEqual(result, TEST_FILE_DICT)
        self.assertIsInstance(result, dict)
Example #6
0
    def test_get_raw(self):
        file_store = File(TEST_FILE_PATH)
        result = file_store.get()

        self.assertEqual(result, TEST_FILE_DICT)
        self.assertIsInstance(result, dict)
Example #7
0
    def test_non_existent_file(self, mock_open):
        simplefilter("ignore")
        file_store = File(TEST_FILE_PATH, encoding="yaml")
        result = file_store.get()

        self.assertEqual(result, {})
Example #8
0
    def test_get_ini_with_section(self):
        file_store = File(TEST_FILE_PATH, encoding="ini")
        result = file_store.get()

        self.assertEqual(result, TEST_FILE_INI_WITH_SECTION_DICT)
        self.assertIsInstance(result, dict)
Example #9
0
    def test_get_ini(self):
        file_store = File(TEST_FILE_PATH, encoding="ini")
        result = file_store.get()

        self.assertEqual(result, TEST_FILE_DICT)
        self.assertIsInstance(result, dict)
Example #10
0
    def test_get_yaml_mergekey(self):
        file_store = File(TEST_FILE_PATH, encoding="yaml")
        result = file_store.get()

        self.assertEqual(result, {})
Example #11
0
    def test_get_json_empty(self):
        file_store = File(TEST_FILE_PATH, encoding="json")
        result = file_store.get()

        self.assertEqual(result, {})
Example #12
0
    def test_non_existent_file(self, mock_open):
        file_store = File(TEST_FILE_PATH, encoding='yaml')
        result = file_store.get()

        self.assertEqual(result, {})
Example #13
0
    def test_get_yaml_empty(self):
        file_store = File(TEST_FILE_PATH, encoding='yaml')
        result = file_store.get()

        self.assertEqual(result, {})