def test_flags(self): cpap_extraction.CONFIG = py_config.config() cpap_extraction.sys.argv = [ "cpap_extraction.py", "-v", "-d", "inputfile.001", "--destination=output" ] input, output_path = cpap_extraction.setup_args() self.assertEqual(input, "inputfile.001") self.assertEqual(output_path, "output") self.assertTrue(cpap_extraction.CONFIG["Verbose"]) self.assertTrue(cpap_extraction.CONFIG["Debug"])
def test_contents(self): test_config = py_config.config() self.assertFalse("Debug" in test_config) self.assertFalse(test_config["Debug"]) self.assertTrue("Debug" in test_config)
def setup(self): test_config = py_config.config() test_config.update({"this": "that"}) return test_config
def test_wrong_filetype(self): test_config = py_config.config() with self.assertWarns(Warning): test_config.set_file_path("NotAJson.txt") self.assertEqual("NotAJson.txt", test_config.config_path)
def test_local_config(self): test_config = py_config.config() with self.assertWarns(Warning): test_config.set_file_path("THISCONFIG.JSON") self.assertEqual("THISCONFIG.JSON", test_config.config_path)
def test_default_value(self): test_config = py_config.config() test_config.set_file_path() expected = os.path.join("cpap_config.json") self.assertEqual(expected, test_config.config_path)
def test_open_file_does_not_exist(self, mocked_os, mocked_file): test_config = py_config.config() with self.assertRaises(FileNotFoundError): test_config.load("invalid/somepath")
def test_open_file_exists(self, mock_json, mocked_os, mocked_file): test_config = py_config.config() test_config.load('Any file') mocked_file.assert_called_once_with('Any file', 'r')