Пример #1
0
 def test_get_config_filename_not_implemented(self):
     test_json = '{"test":1}'
     with pytest.raises(NotImplementedError) as ctx:
         with patch("builtins.open",
                    new_callable=mock_open,
                    read_data=test_json):
             config_obj()
     assert ctx.errisinstance(NotImplementedError)
Пример #2
0
 def test_json_error(self):
     test_json_error = '{"test:1}'
     with pytest.raises(json.JSONDecodeError) as ctx:
         with patch("builtins.open",
                    new_callable=mock_open,
                    read_data=test_json_error):
             config_obj()
     assert ctx.errisinstance(json.JSONDecodeError)
Пример #3
0
 def test_wrong_data_type(self):
     test_json = 0xdeadbeef
     with pytest.raises(TypeError) as ctx:
         with patch("builtins.open",
                    new_callable=mock_open,
                    read_data=test_json):
             config_obj()
     assert ctx.errisinstance(TypeError)
Пример #4
0
 def test_config_file_not_found(self):
     test_json = '{"test":1}'
     with pytest.raises(FileNotFoundError) as ctx:
         with patch("builtins.open",
                    new_callable=mock_open,
                    read_data=test_json):
             with patch("os.path.isfile", lambda x: False):
                 config_obj()
     assert ctx.errisinstance(FileNotFoundError)
Пример #5
0
 def test_base(self):
     test_json = '{"test":1}'
     with patch("builtins.open",
                new_callable=mock_open,
                read_data=test_json):
         some_config = config_obj()
     assert some_config.config == {'test': 1}
     assert some_config.get_config_dict() == {'test': 1}
Пример #6
0
 def test_missing_config_filename(self):
     with pytest.raises(AttributeError) as ctx:
         with patch("builtins.open", lambda x: x):
             config_obj()
     assert ctx.errisinstance(AttributeError)