Пример #1
0
    def test_run_cmd_cache(self):
        """Test caching for run_cmd"""
        (first_out, ec) = run_cmd("ulimit -u")
        self.assertEqual(ec, 0)
        (cached_out, ec) = run_cmd("ulimit -u")
        self.assertEqual(ec, 0)
        self.assertEqual(first_out, cached_out)

        # inject value into cache to check whether executing command again really returns cached value
        run_cmd.update_cache({("ulimit -u", None): ("123456", 123)})
        (cached_out, ec) = run_cmd("ulimit -u")
        self.assertEqual(ec, 123)
        self.assertEqual(cached_out, "123456")

        # also test with command that uses stdin
        (out, ec) = run_cmd("cat", inp='foo')
        self.assertEqual(ec, 0)
        self.assertEqual(out, 'foo')

        # inject different output for cat with 'foo' as stdin to check whether cached value is used
        run_cmd.update_cache({('cat', 'foo'): ('bar', 123)})
        (cached_out, ec) = run_cmd("cat", inp='foo')
        self.assertEqual(ec, 123)
        self.assertEqual(cached_out, 'bar')

        run_cmd.clear_cache()
Пример #2
0
    def test_run_cmd_cache(self):
        """Test caching for run_cmd"""
        (first_out, ec) = run_cmd("ulimit -u")
        self.assertEqual(ec, 0)
        (cached_out, ec) = run_cmd("ulimit -u")
        self.assertEqual(ec, 0)
        self.assertEqual(first_out, cached_out)

        # inject value into cache to check whether executing command again really returns cached value
        run_cmd.update_cache({("ulimit -u", None): ("123456", 123)})
        (cached_out, ec) = run_cmd("ulimit -u")
        self.assertEqual(ec, 123)
        self.assertEqual(cached_out, "123456")

        # also test with command that uses stdin
        (out, ec) = run_cmd("cat", inp='foo')
        self.assertEqual(ec, 0)
        self.assertEqual(out, 'foo')

        # inject different output for cat with 'foo' as stdin to check whether cached value is used
        run_cmd.update_cache({('cat', 'foo'): ('bar', 123)})
        (cached_out, ec) = run_cmd("cat", inp='foo')
        self.assertEqual(ec, 123)
        self.assertEqual(cached_out, 'bar')

        run_cmd.clear_cache()
Пример #3
0
 def test_cpu_family_darwin(self):
     """Test get_cpu_family function (mocked for Darwin)."""
     st.get_os_type = lambda: st.DARWIN
     st.run_cmd = mocked_run_cmd
     run_cmd.clear_cache()
     self.assertEqual(get_cpu_family(), INTEL)
Пример #4
0
 def test_cpu_family_native(self):
     """Test get_cpu_family function."""
     run_cmd.clear_cache()
     cpu_family = get_cpu_family()
     self.assertTrue(cpu_family in CPU_FAMILIES or cpu_family == UNKNOWN)
Пример #5
0
 def test_cpu_family_darwin(self):
     """Test get_cpu_family function (mocked for Darwin)."""
     st.get_os_type = lambda: st.DARWIN
     st.run_cmd = mocked_run_cmd
     run_cmd.clear_cache()
     self.assertEqual(get_cpu_family(), INTEL)
Пример #6
0
 def test_cpu_family_native(self):
     """Test get_cpu_family function."""
     run_cmd.clear_cache()
     cpu_family = get_cpu_family()
     self.assertTrue(cpu_family in CPU_FAMILIES or cpu_family == UNKNOWN)