
import unittest

from blivet.devices import DiskDevice
from blivet.devices import LUKSDevice
from blivet.devices import MDRaidArrayDevice

from blivet.formats import getFormat

class DevicePackagesTestCase(unittest.TestCase):
    """Test device name validation"""

    def testPackages(self):
        dev1 = DiskDevice("name", fmt=getFormat("mdmember"))

        dev2 = DiskDevice("other", fmt=getFormat("mdmember"))
        dev = MDRaidArrayDevice("dev", level="raid1", parents=[dev1,dev2])
        luks = LUKSDevice("luks", parents=[dev])
        packages = luks.packages

        # no duplicates in list of packages
        self.assertListEqual(packages, list(set(packages)))

        # several packages that ought to be included are
        for package in dev1.packages + dev2.packages + dev.packages:
            self.assertIn(package, packages)

        for package in dev1.format.packages + dev2.format.packages + dev.format.packages:
            self.assertIn(package, packages)


import unittest

from blivet.devices import DiskDevice
from blivet.devices import LUKSDevice
from blivet.devices import MDRaidArrayDevice

from blivet.formats import getFormat

class DevicePackagesTestCase(unittest.TestCase):
    """Test device name validation"""

    def testPackages(self):
        dev1 = DiskDevice("name", fmt=getFormat("mdmember"))

        dev2 = DiskDevice("other", fmt=getFormat("mdmember"))
        dev = MDRaidArrayDevice("dev", level="raid1", parents=[dev1,dev2])
        luks = LUKSDevice("luks", parents=[dev])
        packages = luks.packages

        # no duplicates in list of packages
        self.assertEqual(len(packages), len(set(packages)))

        # several packages that ought to be included are
        for package in dev1.packages + dev2.packages + dev.packages:
            self.assertIn(package, packages)

        for package in dev1.format.packages + dev2.format.packages + dev.format.packages:
            self.assertIn(package, packages)

Use len of set to check for duplicates in list of packages.
Use len of set to check for duplicates in list of packages.

Resolves: #154.

Checking for equality of the two lists was a mistake, since
the order of the list generated from the set is undefined.

  
  import unittest
  
  from blivet.devices import DiskDevice
  from blivet.devices import LUKSDevice
  from blivet.devices import MDRaidArrayDevice
  
  from blivet.formats import getFormat
  
  class DevicePackagesTestCase(unittest.TestCase):
      """Test device name validation"""
  
      def testPackages(self):
          dev1 = DiskDevice("name", fmt=getFormat("mdmember"))
  
          dev2 = DiskDevice("other", fmt=getFormat("mdmember"))
          dev = MDRaidArrayDevice("dev", level="raid1", parents=[dev1,dev2])
          luks = LUKSDevice("luks", parents=[dev])
          packages = luks.packages
  
          # no duplicates in list of packages
-         self.assertListEqual(packages, list(set(packages)))
+         self.assertEqual(len(packages), len(set(packages)))
  
          # several packages that ought to be included are
          for package in dev1.packages + dev2.packages + dev.packages:
              self.assertIn(package, packages)
  
          for package in dev1.format.packages + dev2.format.packages + dev.format.packages:
              self.assertIn(package, packages)
  
Use len of set to check for duplicates in list of packages.
## Code Before:

import unittest

from blivet.devices import DiskDevice
from blivet.devices import LUKSDevice
from blivet.devices import MDRaidArrayDevice

from blivet.formats import getFormat

class DevicePackagesTestCase(unittest.TestCase):
    """Test device name validation"""

    def testPackages(self):
        dev1 = DiskDevice("name", fmt=getFormat("mdmember"))

        dev2 = DiskDevice("other", fmt=getFormat("mdmember"))
        dev = MDRaidArrayDevice("dev", level="raid1", parents=[dev1,dev2])
        luks = LUKSDevice("luks", parents=[dev])
        packages = luks.packages

        # no duplicates in list of packages
        self.assertListEqual(packages, list(set(packages)))

        # several packages that ought to be included are
        for package in dev1.packages + dev2.packages + dev.packages:
            self.assertIn(package, packages)

        for package in dev1.format.packages + dev2.format.packages + dev.format.packages:
            self.assertIn(package, packages)

## Instruction:
Use len of set to check for duplicates in list of packages.
## Code After:

import unittest

from blivet.devices import DiskDevice
from blivet.devices import LUKSDevice
from blivet.devices import MDRaidArrayDevice

from blivet.formats import getFormat

class DevicePackagesTestCase(unittest.TestCase):
    """Test device name validation"""

    def testPackages(self):
        dev1 = DiskDevice("name", fmt=getFormat("mdmember"))

        dev2 = DiskDevice("other", fmt=getFormat("mdmember"))
        dev = MDRaidArrayDevice("dev", level="raid1", parents=[dev1,dev2])
        luks = LUKSDevice("luks", parents=[dev])
        packages = luks.packages

        # no duplicates in list of packages
        self.assertEqual(len(packages), len(set(packages)))

        # several packages that ought to be included are
        for package in dev1.packages + dev2.packages + dev.packages:
            self.assertIn(package, packages)

        for package in dev1.format.packages + dev2.format.packages + dev.format.packages:
            self.assertIn(package, packages)
