Ejemplo n.º 1
0
    def test_analyze_dir(self):
        with open(os.devnull, "wb") as dn, redirect_stdout(dn):
            stats = collections.defaultdict(int)
            r = recurse.analyze_dir(stats, __class__.album1_dir,
                                    os.listdir(__class__.album1_dir), "1.jpg",
                                    None, 0)
            self.assertIn("files", stats)
            self.assertEqual(stats["files"], 1)
            self.assertIn("albums", stats)
            self.assertEqual(stats["albums"], 1)
            self.assertIn("missing covers", stats)
            self.assertEqual(stats["missing covers"], 1)
            self.assertNotIn("errors", stats)
            self.assertEqual(r[0], ("ARTIST1", "ALBUM1"))

            stats.clear()
            r = recurse.analyze_dir(stats, __class__.album2_dir,
                                    os.listdir(__class__.album2_dir), "1.jpg",
                                    None, 0)
            self.assertIn("files", stats)
            self.assertEqual(stats["files"], 2)
            self.assertIn("albums", stats)
            self.assertEqual(stats["albums"], 1)
            self.assertIn("missing covers", stats)
            self.assertEqual(stats["missing covers"], 1)
            self.assertNotIn("errors", stats)
            self.assertEqual(r[0], ("ARTIST2", "ALBUM2"))
            stats.clear()
            r = recurse.analyze_dir(stats, __class__.album2_dir,
                                    os.listdir(__class__.album2_dir), "1.dat",
                                    None, 0)
            self.assertIn("files", stats)
            self.assertEqual(stats["files"], 2)
            self.assertIn("albums", stats)
            self.assertEqual(stats["albums"], 1)
            self.assertNotIn("missing covers", stats)
            self.assertNotIn("errors", stats)
            self.assertEqual(r[0], (None, None))

            stats.clear()
            r = recurse.analyze_dir(stats, __class__.not_album_dir,
                                    os.listdir(__class__.not_album_dir),
                                    "1.jpg", None, 0)
            self.assertIn("files", stats)
            self.assertEqual(stats["files"], 1)
            self.assertNotIn("albums", stats)
            self.assertNotIn("missing covers", stats)
            self.assertNotIn("errors", stats)
            self.assertEqual(r[0], (None, None))

            stats.clear()
            r = recurse.analyze_dir(stats, __class__.invalid_album_dir,
                                    os.listdir(__class__.invalid_album_dir),
                                    "1.jpg", None, 0)
            self.assertIn("files", stats)
            self.assertEqual(stats["files"], 2)
            self.assertIn("albums", stats)
            self.assertEqual(stats["albums"], 1)
            self.assertIn("missing covers", stats)
            self.assertEqual(stats["missing covers"], 1)
            self.assertIn("errors", stats)
            self.assertEqual(stats["errors"], 1)
            self.assertEqual(r[0], ("ARTIST1", None))
Ejemplo n.º 2
0
    def test_analyze_dir(self):
        with open(os.devnull, "wt") as dn, contextlib.redirect_stdout(dn):
            stats = collections.defaultdict(int)
            r = recurse.analyze_dir(stats, __class__.album1_dir,
                                    os.listdir(__class__.album1_dir), "1.jpg")
            self.assertIn("files", stats)
            self.assertEqual(stats["files"], 4)
            self.assertIn("albums", stats)
            self.assertEqual(stats["albums"], 1)
            self.assertIn("missing covers", stats)
            self.assertEqual(stats["missing covers"], 1)
            self.assertNotIn("errors", stats)
            self.assertEqual(len(r), 1)
            self.assertEqual(r[0].cover_filepath,
                             os.path.join(__class__.album1_dir, "1.jpg"))
            self.assertEqual(r[0].audio_filepaths,
                             (__class__.album1_filepath, ))
            self.assertEqual(r[0].metadata, Metadata("ARTIST1", "ALBUM1",
                                                     False))

            for regex_matching in (False, True):
                for ignore_existing in (False, True):
                    with self.subTest(regex_matching=regex_matching,
                                      ignore_existing=ignore_existing):
                        stats.clear()
                        image_file_regex = recurse.get_image_file_regex(
                        ) if regex_matching else None
                        r = recurse.analyze_dir(
                            stats,
                            __class__.album2_dir,
                            os.listdir(__class__.album2_dir),
                            "1.jpg",
                            image_file_regex=image_file_regex,
                            ignore_existing=ignore_existing)
                        self.assertIn("files", stats)
                        self.assertEqual(stats["files"], 3)
                        self.assertIn("albums", stats)
                        self.assertEqual(stats["albums"], 1)
                        self.assertNotIn("errors", stats)

                        if regex_matching and not ignore_existing:
                            self.assertNotIn("missing covers", stats)
                            self.assertEqual(len(r), 0)
                        elif ignore_existing or not regex_matching:
                            self.assertIn("missing covers", stats)
                            self.assertEqual(stats["missing covers"], 1)
                            self.assertEqual(len(r), 1)
                            self.assertEqual(
                                r[0].cover_filepath,
                                os.path.join(__class__.album2_dir, "1.jpg"))
                            self.assertEqual(r[0].audio_filepaths,
                                             (__class__.album2_filepath2, ))
                            self.assertEqual(
                                r[0].metadata,
                                Metadata("ARTIST2", "ALBUM2", False))

            stats.clear()
            r = recurse.analyze_dir(stats, __class__.album2_dir,
                                    os.listdir(__class__.album2_dir), "1.dat")
            self.assertIn("files", stats)
            self.assertEqual(stats["files"], 3)
            self.assertIn("albums", stats)
            self.assertEqual(stats["albums"], 1)
            self.assertNotIn("missing covers", stats)
            self.assertNotIn("errors", stats)
            self.assertEqual(len(r), 0)

            stats.clear()
            r = recurse.analyze_dir(stats, __class__.not_album_dir,
                                    os.listdir(__class__.not_album_dir),
                                    "1.jpg")
            self.assertIn("files", stats)
            self.assertEqual(stats["files"], 1)
            self.assertNotIn("albums", stats)
            self.assertNotIn("missing covers", stats)
            self.assertNotIn("errors", stats)
            self.assertEqual(len(r), 0)

            stats.clear()
            r = recurse.analyze_dir(stats, __class__.invalid_album_dir,
                                    os.listdir(__class__.invalid_album_dir),
                                    "1.jpg")
            self.assertIn("files", stats)
            self.assertEqual(stats["files"], 2)
            self.assertIn("errors", stats)
            self.assertEqual(stats["errors"], 1)
            self.assertEqual(len(r), 0)

            open(os.path.join(__class__.album1_dir, "1.jpg"), "wb").close()
            for ignore_existing in (False, True):
                with self.subTest(ignore_existing=ignore_existing):
                    stats.clear()
                    r = recurse.analyze_dir(stats,
                                            __class__.album1_dir,
                                            os.listdir(__class__.album1_dir),
                                            "1.jpg",
                                            ignore_existing=ignore_existing)
                    self.assertIn("files", stats)
                    self.assertEqual(stats["files"], 5)
                    self.assertIn("albums", stats)
                    self.assertEqual(stats["albums"], 1)
                    if not ignore_existing:
                        self.assertNotIn("missing covers", stats)
                        self.assertEqual(len(r), 0)
                    else:
                        self.assertIn("missing covers", stats)
                        self.assertEqual(stats["missing covers"], 1)
                        self.assertEqual(len(r), 1)
                        self.assertEqual(
                            r[0].cover_filepath,
                            os.path.join(__class__.album1_dir, "1.jpg"))
                        self.assertEqual(r[0].audio_filepaths,
                                         (__class__.album1_filepath, ))
                        self.assertEqual(r[0].metadata,
                                         Metadata("ARTIST1", "ALBUM1", False))
                    self.assertNotIn("errors", stats)
        os.remove(os.path.join(__class__.album1_dir, "1.jpg"))
Ejemplo n.º 3
0
  def test_analyze_dir(self):
    with open(os.devnull, "wb") as dn, redirect_stdout(dn):
      stats = collections.defaultdict(int)
      r = recurse.analyze_dir(stats,
                              __class__.album1_dir,
                              os.listdir(__class__.album1_dir),
                              "1.jpg",
                              None,
                              0)
      self.assertIn("files", stats)
      self.assertEqual(stats["files"], 1)
      self.assertIn("albums", stats)
      self.assertEqual(stats["albums"], 1)
      self.assertIn("missing covers", stats)
      self.assertEqual(stats["missing covers"], 1)
      self.assertNotIn("errors", stats)
      self.assertEqual(r[0], ("ARTIST1", "ALBUM1"))

      stats.clear()
      r = recurse.analyze_dir(stats,
                              __class__.album2_dir,
                              os.listdir(__class__.album2_dir),
                              "1.jpg",
                              None,
                              0)
      self.assertIn("files", stats)
      self.assertEqual(stats["files"], 2)
      self.assertIn("albums", stats)
      self.assertEqual(stats["albums"], 1)
      self.assertIn("missing covers", stats)
      self.assertEqual(stats["missing covers"], 1)
      self.assertNotIn("errors", stats)
      self.assertEqual(r[0], ("ARTIST2", "ALBUM2"))
      stats.clear()
      r = recurse.analyze_dir(stats,
                              __class__.album2_dir,
                              os.listdir(__class__.album2_dir),
                              "1.dat",
                              None,
                              0)
      self.assertIn("files", stats)
      self.assertEqual(stats["files"], 2)
      self.assertIn("albums", stats)
      self.assertEqual(stats["albums"], 1)
      self.assertNotIn("missing covers", stats)
      self.assertNotIn("errors", stats)
      self.assertEqual(r[0], (None, None))

      stats.clear()
      r = recurse.analyze_dir(stats,
                              __class__.not_album_dir,
                              os.listdir(__class__.not_album_dir),
                              "1.jpg",
                              None,
                              0)
      self.assertIn("files", stats)
      self.assertEqual(stats["files"], 1)
      self.assertNotIn("albums", stats)
      self.assertNotIn("missing covers", stats)
      self.assertNotIn("errors", stats)
      self.assertEqual(r[0], (None, None))

      stats.clear()
      r = recurse.analyze_dir(stats,
                              __class__.invalid_album_dir,
                              os.listdir(__class__.invalid_album_dir),
                              "1.jpg",
                              None,
                              0)
      self.assertIn("files", stats)
      self.assertEqual(stats["files"], 2)
      self.assertIn("albums", stats)
      self.assertEqual(stats["albums"], 1)
      self.assertIn("missing covers", stats)
      self.assertEqual(stats["missing covers"], 1)
      self.assertIn("errors", stats)
      self.assertEqual(stats["errors"], 1)
      self.assertEqual(r[0], ("ARTIST1", None))
Ejemplo n.º 4
0
    def test_analyze_dir(self):
        stats = collections.defaultdict(int)
        r = recurse.analyze_dir(stats, __class__.album1_dir,
                                os.listdir(__class__.album1_dir), "1.jpg")
        self.assertIn("files", stats)
        self.assertEqual(stats["files"], 1)
        self.assertIn("albums", stats)
        self.assertEqual(stats["albums"], 1)
        self.assertIn("missing covers", stats)
        self.assertEqual(stats["missing covers"], 1)
        self.assertNotIn("errors", stats)
        self.assertEqual(len(r), 1)
        self.assertEqual(r[0].cover_filepath,
                         os.path.join(__class__.album1_dir, "1.jpg"))
        self.assertEqual(r[0].audio_filepaths, (__class__.album1_filepath, ))
        self.assertEqual(r[0].metadata, Metadata("ARTIST1", "ALBUM1", False))

        for all_formats in (False, True):
            for format_ext in ("jpg", "jpeg"):
                with self.subTest(all_formats=all_formats,
                                  format_ext=format_ext):
                    stats.clear()
                    r = recurse.analyze_dir(stats,
                                            __class__.album2_dir,
                                            os.listdir(__class__.album2_dir),
                                            "1.%s" % (format_ext),
                                            all_formats=all_formats)
                    self.assertIn("files", stats)
                    self.assertEqual(stats["files"], 3)
                    self.assertIn("albums", stats)
                    self.assertEqual(stats["albums"], 1)
                    if all_formats:
                        self.assertNotIn("missing covers", stats)
                        self.assertEqual(len(r), 0)
                    else:
                        self.assertIn("missing covers", stats)
                        self.assertEqual(stats["missing covers"], 1)
                        self.assertEqual(len(r), 1)
                        self.assertEqual(
                            r[0].cover_filepath,
                            os.path.join(__class__.album2_dir,
                                         "1.%s" % (format_ext)))
                        self.assertEqual(r[0].audio_filepaths,
                                         (__class__.album2_filepath2, ))
                        self.assertEqual(r[0].metadata,
                                         Metadata("ARTIST2", "ALBUM2", False))
                    self.assertNotIn("errors", stats)

            stats.clear()
            r = recurse.analyze_dir(stats, __class__.album2_dir,
                                    os.listdir(__class__.album2_dir), "1.dat")
            self.assertIn("files", stats)
            self.assertEqual(stats["files"], 3)
            self.assertIn("albums", stats)
            self.assertEqual(stats["albums"], 1)
            self.assertNotIn("missing covers", stats)
            self.assertNotIn("errors", stats)
            self.assertEqual(len(r), 0)

            stats.clear()
            r = recurse.analyze_dir(stats, __class__.not_album_dir,
                                    os.listdir(__class__.not_album_dir),
                                    "1.jpg")
            self.assertIn("files", stats)
            self.assertEqual(stats["files"], 1)
            self.assertNotIn("albums", stats)
            self.assertNotIn("missing covers", stats)
            self.assertNotIn("errors", stats)
            self.assertEqual(len(r), 0)

            stats.clear()
            r = recurse.analyze_dir(stats, __class__.invalid_album_dir,
                                    os.listdir(__class__.invalid_album_dir),
                                    "1.jpg")
            self.assertIn("files", stats)
            self.assertEqual(stats["files"], 2)
            self.assertIn("errors", stats)
            self.assertEqual(stats["errors"], 1)
            self.assertEqual(len(r), 0)

            open(os.path.join(__class__.album1_dir, "1.jpg"), "wb").close()
            for ignore_existing in (False, True):
                with self.subTest(ignore_existing=ignore_existing):
                    stats.clear()
                    r = recurse.analyze_dir(stats,
                                            __class__.album1_dir,
                                            os.listdir(__class__.album1_dir),
                                            "1.jpg",
                                            ignore_existing=ignore_existing)
                    self.assertIn("files", stats)
                    self.assertEqual(stats["files"], 2)
                    self.assertIn("albums", stats)
                    self.assertEqual(stats["albums"], 1)
                    if not ignore_existing:
                        self.assertNotIn("missing covers", stats)
                        self.assertEqual(len(r), 0)
                    else:
                        self.assertIn("missing covers", stats)
                        self.assertEqual(stats["missing covers"], 1)
                        self.assertEqual(len(r), 1)
                        self.assertEqual(
                            r[0].cover_filepath,
                            os.path.join(__class__.album1_dir, "1.jpg"))
                        self.assertEqual(r[0].audio_filepaths,
                                         (__class__.album1_filepath, ))
                        self.assertEqual(r[0].metadata,
                                         Metadata("ARTIST1", "ALBUM1", False))
                    self.assertNotIn("errors", stats)
Ejemplo n.º 5
0
    def test_analyze_dir(self):
        with open(os.devnull, "wt") as dn, contextlib.redirect_stdout(dn):
            stats = collections.defaultdict(int)
            failed_dirs = []
            r = recurse.analyze_dir(stats, __class__.album1_dir,
                                    os.listdir(__class__.album1_dir), "1.jpg",
                                    failed_dirs)
            self.assertIn("files", stats)
            self.assertEqual(stats["files"], 1)
            self.assertIn("albums", stats)
            self.assertEqual(stats["albums"], 1)
            self.assertIn("missing covers", stats)
            self.assertEqual(stats["missing covers"], 1)
            self.assertNotIn("errors", stats)
            self.assertEqual(len(failed_dirs), 0)
            self.assertEqual(r, ("ARTIST1", "ALBUM1", False))

            stats.clear()
            r = recurse.analyze_dir(stats, __class__.album2_dir,
                                    os.listdir(__class__.album2_dir), "1.jpg",
                                    failed_dirs)
            self.assertIn("files", stats)
            self.assertEqual(stats["files"], 2)
            self.assertIn("albums", stats)
            self.assertEqual(stats["albums"], 1)
            self.assertIn("missing covers", stats)
            self.assertEqual(stats["missing covers"], 1)
            self.assertNotIn("errors", stats)
            self.assertEqual(len(failed_dirs), 0)
            self.assertEqual(r, ("ARTIST2", "ALBUM2", False))
            stats.clear()
            r = recurse.analyze_dir(stats, __class__.album2_dir,
                                    os.listdir(__class__.album2_dir), "1.dat",
                                    failed_dirs)
            self.assertIn("files", stats)
            self.assertEqual(stats["files"], 2)
            self.assertIn("albums", stats)
            self.assertEqual(stats["albums"], 1)
            self.assertNotIn("missing covers", stats)
            self.assertNotIn("errors", stats)
            self.assertEqual(len(failed_dirs), 0)
            self.assertEqual(r, (None, None, None))

            stats.clear()
            failed_dirs.clear()
            r = recurse.analyze_dir(stats, __class__.not_album_dir,
                                    os.listdir(__class__.not_album_dir),
                                    "1.jpg", failed_dirs)
            self.assertIn("files", stats)
            self.assertEqual(stats["files"], 1)
            self.assertNotIn("albums", stats)
            self.assertNotIn("missing covers", stats)
            self.assertNotIn("errors", stats)
            self.assertEqual(len(failed_dirs), 0)
            self.assertEqual(r, (None, None, None))

            stats.clear()
            failed_dirs.clear()
            r = recurse.analyze_dir(stats, __class__.invalid_album_dir,
                                    os.listdir(__class__.invalid_album_dir),
                                    "1.jpg", failed_dirs)
            self.assertIn("files", stats)
            self.assertEqual(stats["files"], 2)
            self.assertIn("albums", stats)
            self.assertEqual(stats["albums"], 1)
            self.assertIn("missing covers", stats)
            self.assertEqual(stats["missing covers"], 1)
            self.assertIn("errors", stats)
            self.assertEqual(stats["errors"], 1)
            self.assertSequenceEqual(failed_dirs,
                                     (__class__.invalid_album_dir, ))
            self.assertEqual(r, ("ARTIST1", None, None))
Ejemplo n.º 6
0
  def test_analyze_dir(self):
    with open(os.devnull, "wt") as dn, contextlib.redirect_stdout(dn):
      stats = collections.defaultdict(int)
      r = recurse.analyze_dir(stats,
                              __class__.album1_dir,
                              os.listdir(__class__.album1_dir),
                              "1.jpg")
      self.assertIn("files", stats)
      self.assertEqual(stats["files"], 1)
      self.assertIn("albums", stats)
      self.assertEqual(stats["albums"], 1)
      self.assertIn("missing covers", stats)
      self.assertEqual(stats["missing covers"], 1)
      self.assertNotIn("errors", stats)
      self.assertEqual(r, ("ARTIST1", "ALBUM1", False))

      stats.clear()
      r = recurse.analyze_dir(stats,
                              __class__.album2_dir,
                              os.listdir(__class__.album2_dir),
                              "1.jpg")
      self.assertIn("files", stats)
      self.assertEqual(stats["files"], 2)
      self.assertIn("albums", stats)
      self.assertEqual(stats["albums"], 1)
      self.assertIn("missing covers", stats)
      self.assertEqual(stats["missing covers"], 1)
      self.assertNotIn("errors", stats)
      self.assertEqual(r, ("ARTIST2", "ALBUM2", False))
      stats.clear()
      r = recurse.analyze_dir(stats,
                              __class__.album2_dir,
                              os.listdir(__class__.album2_dir),
                              "1.dat")
      self.assertIn("files", stats)
      self.assertEqual(stats["files"], 2)
      self.assertIn("albums", stats)
      self.assertEqual(stats["albums"], 1)
      self.assertNotIn("missing covers", stats)
      self.assertNotIn("errors", stats)
      self.assertEqual(r, (None, None, None))

      stats.clear()
      r = recurse.analyze_dir(stats,
                              __class__.not_album_dir,
                              os.listdir(__class__.not_album_dir),
                              "1.jpg")
      self.assertIn("files", stats)
      self.assertEqual(stats["files"], 1)
      self.assertNotIn("albums", stats)
      self.assertNotIn("missing covers", stats)
      self.assertNotIn("errors", stats)
      self.assertEqual(r, (None, None, None))

      stats.clear()
      r = recurse.analyze_dir(stats,
                              __class__.invalid_album_dir,
                              os.listdir(__class__.invalid_album_dir),
                              "1.jpg")
      self.assertIn("files", stats)
      self.assertEqual(stats["files"], 2)
      self.assertIn("albums", stats)
      self.assertEqual(stats["albums"], 1)
      self.assertIn("missing covers", stats)
      self.assertEqual(stats["missing covers"], 1)
      self.assertIn("errors", stats)
      self.assertEqual(stats["errors"], 1)
      self.assertEqual(r, ("ARTIST1", None, None))

      open(os.path.join(__class__.album1_dir, "1.jpg"), "wb").close()
      for ignore_existing in (False, True):
        stats.clear()
        r = recurse.analyze_dir(stats,
                                __class__.album1_dir,
                                os.listdir(__class__.album1_dir),
                                "1.jpg",
                                ignore_existing=ignore_existing)
        self.assertIn("files", stats)
        self.assertEqual(stats["files"], 2)
        self.assertIn("albums", stats)
        self.assertEqual(stats["albums"], 1)
        if not ignore_existing:
          self.assertNotIn("missing covers", stats)
          self.assertEqual(r, (None, None, None))
        else:
          self.assertIn("missing covers", stats)
          self.assertEqual(stats["missing covers"], 1)
          self.assertEqual(r, ("ARTIST1", "ALBUM1", False))
        self.assertNotIn("errors", stats)