def test_json(self): argv = build_argv(self.optional, self.positional) with captured_output(argv) as (out, err): sut.main() validate_json(self.actual_file, fixtureToAbsolute('utf-8.json')) actual_print = out.getvalue().strip() self.assertEqual('2 rows processed', actual_print)
def test_switch_fields(self): self.optional.extend( ['--fields', fixtureToAbsolute('fields-good.txt')]) argv = build_argv(self.optional, self.positional) with captured_output(argv) as (out, err): sut.main() validate_json(self.actual_file, fixtureToAbsolute('utf-8-switched.json'))
def test_switch_fields_too_many(self): self.optional.extend(['--fields', fixtureToAbsolute('fields-bad.txt')]) argv = build_argv(self.optional, self.positional) with self.assertRaises(SystemExit) as ex: with captured_output(argv) as (out, err): sut.main() actual_print = err.getvalue().strip() self.assertIn('has 4 fields. Expected 3', actual_print) # assert exit code self.assertEqual(ex.exception.code, 2)
def test_switch_fields_too_many(self): self.optional.extend( ['--fields', fixtureToAbsolute('fields-bad.txt')] ) argv = build_argv(self.optional, self.positional) with captured_output(argv) as (out, err): sut.main() # Still processes! validate_json(self.actual_file, fixtureToAbsolute('utf-8.json')) actual_print = err.getvalue().strip() self.assertIn('has 4 fields. Expected 3', actual_print)