def test_config_nameorder_default(self) -> None: """Tests config: nameorder: default.""" def mock_convert(config: Dict[str, str]) -> None: self.assertEqual(config["nameorder"], "little") argv = [""] with unittest.mock.patch('sys.argv', argv): with unittest.mock.patch('ged2dot.convert', mock_convert): ged2dot.main()
def test_config_nameorder_custom(self) -> None: """Tests config: nameorder: custom.""" def mock_convert(config: Dict[str, str]) -> None: self.assertEqual(config["nameorder"], "big") argv = ["", "--nameorder", "big"] with unittest.mock.patch('sys.argv', argv): with unittest.mock.patch('ged2dot.convert', mock_convert): ged2dot.main()
def test_config_familydepth_custom(self) -> None: """Tests config: familydepth: custom.""" def mock_convert(config: Dict[str, str]) -> None: self.assertEqual(config["familydepth"], "0") argv = ["", "--familydepth", "0"] with unittest.mock.patch('sys.argv', argv): with unittest.mock.patch('ged2dot.convert', mock_convert): ged2dot.main()
def test_config_imagedir_custom(self) -> None: """Tests config: imagedir: custom.""" def mock_convert(config: Dict[str, str]) -> None: self.assertEqual(config["imagedir"], "myimagedir") argv = ["", "--imagedir", "myimagedir"] with unittest.mock.patch('sys.argv', argv): with unittest.mock.patch('ged2dot.convert', mock_convert): ged2dot.main()
def test_config_rootfamily_custom(self) -> None: """Tests config: rootfamily: custom.""" def mock_convert(config: Dict[str, str]) -> None: self.assertEqual(config["rootfamily"], "F42") argv = ["", "--rootfamily", "F42"] with unittest.mock.patch('sys.argv', argv): with unittest.mock.patch('ged2dot.convert', mock_convert): ged2dot.main()
def test_config_output_custom(self) -> None: """Tests config: output: custom.""" def mock_convert(config: Dict[str, str]) -> None: self.assertEqual(config["output"], "test.ged") argv = ["", "--output", "test.ged"] with unittest.mock.patch('sys.argv', argv): with unittest.mock.patch('ged2dot.convert', mock_convert): ged2dot.main()
def test_config(self) -> None: """Tests the case when there is a ged2dotrc in the current dir.""" pwd = os.getcwd() os.chdir("tests/config") try: if os.path.exists("hello.dot"): os.unlink("hello.dot") self.assertFalse(os.path.exists("hello.dot")) argv = ["", "--config", "ged2dotrc"] with unittest.mock.patch('sys.argv', argv): ged2dot.main() self.assertTrue(os.path.exists("hello.dot")) finally: os.chdir(pwd)
def test_config_output_default(self) -> None: """Tests config: output: default.""" def mock_convert(config: Dict[str, str]) -> None: self.assertEqual(config["output"], "-") argv = [""] with unittest.mock.patch('sys.argv', argv): with unittest.mock.patch('ged2dot.convert', mock_convert): ged2dot.main() # Now test writing to stdout. argv = ["", "--input", "tests/happy.ged"] stdout = BufferHolder() with unittest.mock.patch('sys.argv', argv): with unittest.mock.patch('sys.stdout', stdout): ged2dot.main() stdout.buffer.seek(0) actual = stdout.buffer.read() self.assertTrue(actual.startswith(b"// Generated by "))
def test_config_input_default(self) -> None: """Tests config: input: default.""" def mock_convert(config: Dict[str, str]) -> None: self.assertEqual(config["input"], "-") argv = [""] with unittest.mock.patch('sys.argv', argv): with unittest.mock.patch('ged2dot.convert', mock_convert): ged2dot.main() # Now test reading from stdin. argv = ["", "--output", "tests/output.dot"] stdin = BufferHolder() with open("tests/happy.ged", "rb") as stream: stdin.buffer.write(stream.read()) stdin.buffer.seek(0) with unittest.mock.patch('sys.argv', argv): with unittest.mock.patch('sys.stdin', stdin): ged2dot.main()