def check(self, original, modified, expected, test_name='check', options=None, directory=TEMP_DIR): """Modify original to modified, and check that pep8radius turns this into expected.""" os.chdir(directory) if not self.using_vc: raise SkipTest("%s not available" % self.vc) temp_file = os.path.join(TEMP_DIR, 'temp.py') options = parse_args(options) with open(temp_file, 'w') as f: f.write(original) committed = self.successfully_commit_files([temp_file], commit=test_name) with open(temp_file, 'w') as f: f.write(modified) options.verbose = 1 r = Radius.new(vc=self.vc, options=options) with captured_output() as (out, err): r.pep8radius() self.assertIn('would fix', out.getvalue()) self.assertNotIn('@@', out.getvalue()) options.verbose = 0 options.diff = True r = Radius.new(vc=self.vc, options=options) with captured_output() as (out, err): r.pep8radius() exp_diff = get_diff(modified, expected, temp_file) # last char in getvalue is an additional new line self.assertEqual(exp_diff, out.getvalue()[:-1]) options.diff = False options.in_place = True r = Radius.new(vc=self.vc, options=options) # Run pep8radius r.pep8radius() with open(temp_file, 'r') as f: result = f.read() self.assert_equal(result, expected, test_name) # Run pep8radius again, it *should* be that this doesn't do anything. r.pep8radius() with open(temp_file, 'r') as f: result = f.read() self.assert_equal(result, expected, test_name)
def test_autopep8_args(self): # TODO see that these are passes on (use a static method in Radius?) args = ["hello.py"] us = parse_args(args) them = autopep8.parse_args(args) self.assertEqual(us.select, them.select) self.assertEqual(us.ignore, them.ignore) args = ["hello.py", "--select=E1,W1", "--ignore=W601", "--max-line-length", "120"] us = parse_args(args) them = autopep8.parse_args(args) self.assertEqual(us.select, them.select) self.assertEqual(us.ignore, them.ignore) self.assertEqual(us.max_line_length, them.max_line_length) args = ["hello.py", "--aggressive", "-v"] us = parse_args(args) them = autopep8.parse_args(args) self.assertEqual(us.aggressive, them.aggressive)
def check(self, original, modified, expected, test_name="check", options=None, directory=TEMP_DIR): """Modify original to modified, and check that pep8radius turns this into expected.""" os.chdir(directory) if not self.using_vc: raise SkipTest("%s not available" % self.vc) temp_file = os.path.join(TEMP_DIR, "temp.py") options = parse_args(options) with open(temp_file, "w") as f: f.write(original) committed = self.successfully_commit_files([temp_file], commit=test_name) with open(temp_file, "w") as f: f.write(modified) options.verbose = 1 r = Radius.new(vc=self.vc, options=options) with captured_output() as (out, err): r.pep8radius() self.assertIn("would fix", out.getvalue()) self.assertNotIn("@@", out.getvalue()) options.verbose = 0 options.diff = True r = Radius.new(vc=self.vc, options=options) with captured_output() as (out, err): r.pep8radius() exp_diff = get_diff(modified, expected, temp_file) # last char in getvalue is an additional new line self.assertEqual(exp_diff, out.getvalue()[:-1]) options.diff = False options.in_place = True r = Radius.new(vc=self.vc, options=options) # Run pep8radius r.pep8radius() with open(temp_file, "r") as f: result = f.read() self.assert_equal(result, expected, test_name) # Run pep8radius again, it *should* be that this doesn't do anything. r.pep8radius() with open(temp_file, "r") as f: result = f.read() self.assert_equal(result, expected, test_name)
def test_autopep8_args(self): # TODO see that these are passes on (use a static method in Radius?) args = ['hello.py'] us = parse_args(args) them = autopep8.parse_args(args) self.assertEqual(us.select, them.select) self.assertEqual(us.ignore, them.ignore) args = [ 'hello.py', '--select=E1,W1', '--ignore=W601', '--max-line-length', '120' ] us = parse_args(args) them = autopep8.parse_args(args) self.assertEqual(us.select, them.select) self.assertEqual(us.ignore, them.ignore) self.assertEqual(us.max_line_length, them.max_line_length) args = ['hello.py', '--aggressive', '-v'] us = parse_args(args) them = autopep8.parse_args(args) self.assertEqual(us.aggressive, them.aggressive)