Esempio n. 1
0
  def test_processor_indent_show_output_text(self):
    self.config.set_verbose(4)  # Ensure output text.

    # Trigger SourceVisitor.__nprint() while visiting AST, which is one way to add some output text.
    self.config.set_print_visits(True)

    fp = ScopedTemporaryFile()
    fp.write(b"""def foo(): pass
foo()              # Ignoring member 'foo' because it's user-defined!
import Queue
class Queue: pass  # Ignoring module 'Queue' because it's user-defined!
def any(): pass
any(test=1)        # Ignoring function 'any' because it's user-defined!
print('hello')     # print(expr) requires 2+ or 3+
""")
    fp.close()
    paths = [fp.path()]
    processor = Processor()
    (mins, incomp, unique_versions, backports) = processor.process(paths, self.config)

    if current_version() >= (3, 0):
      self.assertEqual(mins, [(2, 0), (3, 0)])
      self.assertEqual(unique_versions, [(2, 0), (3, 0)])
    else:  # pragma: no cover
      self.assertEqual(mins, [(2, 0), (0, 0)])
      self.assertEqual(unique_versions, [(2, 0)])

    self.assertFalse(incomp)
    self.assertEmpty(backports)
Esempio n. 2
0
 def test_detect_vermin_min_versions_parsable(self):
   paths = detect_paths([abspath("vermin")])
   processor = Processor()
   self.config.set_format(ParsableFormat())
   (mins, _incomp, _unique_versions, backports) = processor.process(paths, self.config)
   self.assertOnlyIn(((2, 7), (3, 0)), mins)
   self.assertEmpty(backports)
Esempio n. 3
0
 def test_detect_vermin_min_versions(self):
     paths = detect_paths([abspath("vermin")])
     processor = Processor()
     (mins, _incomp, _unique_versions, backports, used_novermin) =\
       processor.process(paths, self.config)
     self.assertOnlyIn(((2, 7), (3, 0)), mins)
     self.assertEmpty(backports)
     self.assertTrue(used_novermin)
Esempio n. 4
0
 def test_processor_value_error(self):
   fp = ScopedTemporaryFile()
   fp.write(b"\0")
   fp.close()
   paths = [fp.path()]
   processor = Processor()
   (mins, incomp, unique_versions, backports) = processor.process(paths, self.config)
   self.assertEqual(mins, [(0, 0), (0, 0)])
   self.assertFalse(incomp)
   self.assertEmpty(unique_versions)
   self.assertEmpty(backports)
Esempio n. 5
0
 def test_processor_argparse_backport_spawn_or_fork(self):
   fp = ScopedTemporaryFile()
   fp.writeln(b"import argparse")  # 2.7, 3.2
   fp.close()
   self.config.add_backport("argparse")  # -> 2.3, 3.1
   paths = [fp.path()]
   processor = Processor()
   (mins, incomp, unique_versions, backports) = processor.process(paths, self.config)
   self.assertEqual(mins, [(2, 3), (3, 1)])
   self.assertFalse(incomp)
   self.assertEqual(unique_versions, [(2, 3), (3, 1)])
   self.assertEqual(backports, {"argparse"})
Esempio n. 6
0
 def test_processor_incompatible(self):
   fp = ScopedTemporaryFile()
   fp.writeln(b"import Queue")  # 2.0, !3
   fp.writeln(b"import builtins")  # !2, 3.0
   fp.close()
   paths = [fp.path()]
   processor = Processor()
   (mins, incomp, unique_versions, backports) = processor.process(paths, self.config)
   self.assertEqual(mins, [(0, 0), (0, 0)])
   self.assertTrue(incomp)
   self.assertEmpty(unique_versions)
   self.assertEmpty(backports)
Esempio n. 7
0
 def test_processor_used_novermin(self):
     fp = ScopedTemporaryFile()
     fp.writeln(b"import Queue  # novm")  # 2.0, !3
     fp.writeln(b"import builtins")  # !2, 3.0
     fp.close()
     paths = [fp.path()]
     processor = Processor()
     (mins, incomp, unique_versions, backports, used_novermin) =\
       processor.process(paths, self.config)
     print(mins)
     self.assertEqual(mins, [None, (3, 0)])
     self.assertFalse(incomp)
     self.assertEqual(unique_versions, [(3, 0)])
     self.assertEmpty(backports)
     self.assertTrue(used_novermin)
Esempio n. 8
0
  def test_processor_separately_incompatible(self):
    paths = []
    codes = [
      b"import Queue\n",  # 2.0, !3
      b"import builtins\n",  # !2, 3.0
    ]
    for code in codes:
      fp = NamedTemporaryFile(suffix=".py", delete=False)
      fp.write(code)
      fp.close()
      paths.append(fp.name)

    processor = Processor()
    (mins, incomp, unique_versions, backports) = processor.process(paths, self.config)
    self.assertEqual(mins, [(2, 0), None])  # Because the Queue file is analyzed first.
    self.assertTrue(incomp)
    self.assertEqual(unique_versions, [(2, 0), (3, 0)])
    self.assertEmpty(backports)

    for path in paths:
      os.remove(path)
Esempio n. 9
0
 def test_detect_vermin_min_versions(self):
     paths = detect_paths([abspath("vermin")])
     processor = Processor()
     (mins, incomp, unique_versions, backports) = processor.process(paths)
     self.assertOnlyIn(((2, 7), (3, 0)), mins)
     self.assertEmpty(backports)
Esempio n. 10
0
 def test_detect_vermin_min_versions(self):
     paths = detect_paths([abspath("vermin")])
     processor = Processor()
     (mins, incomp, unique_versions) = processor.process(paths)
     self.assertOnlyIn((2.7, 3.0), mins)