コード例 #1
0
  def testFourDimensions(self):
    """Test TruthTable behavior for four boolean inputs."""
    false1 = (True, True, True, False)
    false2 = (True, False, True, False)
    true1 = (False, True, False, True)
    true2 = (True, True, False, False)
    tt = cros_test_lib.TruthTable(inputs=(false1, false2), input_result=False)
    self.assertEquals(len(tt), pow(2, 4))

    # Check truth table output.
    self.assertFalse(tt.GetOutput(false1))
    self.assertFalse(tt.GetOutput(false2))
    self.assertTrue(tt.GetOutput(true1))
    self.assertTrue(tt.GetOutput(true2))

    # Check assertions on bad input to GetOutput.
    self.assertRaises(TypeError, tt.GetOutput, True)
    self.assertRaises(ValueError, tt.GetOutput, (True, True, True))

    # Check iteration over input lines.
    lines = list(tt)
    self.assertEquals((False, False, False, False), lines[0])
    self.assertEquals((False, False, False, True), lines[1])
    self.assertEquals((False, True, True, True), lines[7])
    self.assertEquals((True, True, True, True), lines[15])

    self._TestTableSanity(tt, lines)
コード例 #2
0
    def testDualEnableSetting(self):
        settings = {
            'prebuilts': 'ShouldUploadPrebuilts',
            'postsync_patch': 'ShouldPatchAfterSync',
        }

        # Both option and config enabled should result in True.
        # Create truth table with three variables in this order:
        # <key> option value, <key> config value (e.g. <key> == 'prebuilts').
        truth_table = cros_test_lib.TruthTable(inputs=[(True, True)])

        for inputs in truth_table:
            option_val, config_val = inputs
            for key, accessor in settings.iteritems():
                self.assertEquals(
                    self._RunAccessor(accessor, {key: option_val},
                                      {key: config_val}),
                    truth_table.GetOutput(inputs))
コード例 #3
0
    def testShouldReexecAfterSync(self):
        # If option and config have postsync_reexec enabled, and this file is not
        # in the build root, then we expect ShouldReexecAfterSync to return True.

        # Construct a truth table across three variables in this order:
        # postsync_reexec option value, postsync_reexec config value, same_root.
        truth_table = cros_test_lib.TruthTable(inputs=[(True, True, False)])

        for inputs in truth_table:
            option_val, config_val, same_root = inputs

            if same_root:
                build_root = os.path.dirname(os.path.dirname(__file__))
            else:
                build_root = DEFAULT_BUILDROOT

            result = self._RunAccessor('ShouldReexecAfterSync', {
                'postsync_reexec': option_val,
                'buildroot': build_root
            }, {'postsync_reexec': config_val})

            self.assertEquals(result, truth_table.GetOutput(inputs))
コード例 #4
0
  def testTwoDimensions(self):
    """Test TruthTable behavior for two boolean inputs."""
    tt = cros_test_lib.TruthTable(inputs=[(True, True), (True, False)])
    self.assertEquals(len(tt), pow(2, 2))

    # Check truth table output.
    self.assertFalse(tt.GetOutput((False, False)))
    self.assertFalse(tt.GetOutput((False, True)))
    self.assertTrue(tt.GetOutput((True, False)))
    self.assertTrue(tt.GetOutput((True, True)))

    # Check assertions on bad input to GetOutput.
    self.assertRaises(TypeError, tt.GetOutput, True)
    self.assertRaises(ValueError, tt.GetOutput, (True, True, True))

    # Check iteration over input lines.
    lines = list(tt)
    self.assertEquals((False, False), lines[0])
    self.assertEquals((False, True), lines[1])
    self.assertEquals((True, False), lines[2])
    self.assertEquals((True, True), lines[3])

    self._TestTableSanity(tt, lines)