Esempio n. 1
0
    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)
Esempio n. 2
0
    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)
Esempio n. 3
0
 def test_unknown_vc(self):
     # we have pep8radius is uing git...
     self.assertTrue(isinstance(Radius.new(None), RadiusGit))
Esempio n. 4
0
 def test_bad_vc(self):
     self.assertRaises(NotImplementedError, lambda x: Radius.new(vc=x), "made_up_vc")
Esempio n. 5
0
 def test_bad_rev(self):
     self.assertRaises(CalledProcessError, lambda x: Radius.new(rev=x), "random_junk_sha")
Esempio n. 6
0
 def test_unknown_vc(self):
     # we have pep8radius is uing git...
     self.assertTrue(isinstance(Radius.new(None), RadiusGit))
Esempio n. 7
0
 def test_bad_vc(self):
     self.assertRaises(NotImplementedError, lambda x: Radius.new(vc=x),
                       'made_up_vc')
Esempio n. 8
0
 def test_bad_rev(self):
     self.assertRaises(CalledProcessError, lambda x: Radius.new(rev=x),
                       'random_junk_sha')