Exemplo n.º 1
0
def test_find_wp_version(mock_open_file):
	mockFile = mock.MagicMock(spec=file)
	mock_open_file.return_value = mockFile
	mockFile.__iter__ = mock.Mock(return_value=iter(['abc', 'def', 'ghi']))
	res = wpa.find_wp_version('file.txt')
	mock_open_file.assert_called_with('file.txt', 'r')
	assert_false(res)

	mockFile.__iter__ = mock.Mock(return_value=iter(['abc', "$wp_version == '1.2.3'", 'ghi']))
	res = wpa.find_wp_version('file.txt')
	assert_equal(res, '1.2.3')

	mock_open_file.return_value = False
	res = wpa.find_wp_version('notafile.txt')
	assert_false(res)
Exemplo n.º 2
0
def test_find_wp_version(mock_search_file):
	mock_search_file.return_value = False
	res = wpa.find_wp_version('file.php')
	mock_search_file.assert_called_with('file.php', '$wp_version =')
	assert_false(res)

	mock_search_file.return_value = "$wp_version = \n"
	res = wpa.find_wp_version('file.php')
	mock_search_file.assert_called_with('file.php', '$wp_version =')
	assert_false(res)

	mock_search_file.return_value = "$wp_version = '1.2.3'\n"
	res = wpa.find_wp_version('file.php')
	mock_search_file.assert_called_with('file.php', '$wp_version =')
	assert_equal(res, '1.2.3')
Exemplo n.º 3
0
def test_find_wp_version(mock_open_file):
	mockFile = mock.MagicMock(spec=file)
	mock_open_file.return_value = mockFile
	mockFile.__iter__ = mock.Mock(return_value=iter(['abc', 'def', 'ghi']))
	res = wpa.find_wp_version('file.txt')
	mock_open_file.assert_called_with('file.txt', 'r')
	assert_false(res)

	mockFile.__iter__ = mock.Mock(return_value=iter(['abc', "$wp_version == '1.2.3'", 'ghi']))
	res = wpa.find_wp_version('file.txt')
	assert_equal(res, '1.2.3')

	mock_open_file.return_value = False
	res = wpa.find_wp_version('notafile.txt')
	assert_false(res)