fix(test): mock caches and everything else
This commit is contained in:
parent
1822714a0c
commit
373e7f6e76
5 changed files with 51 additions and 5 deletions
|
|
@ -91,7 +91,8 @@ local function setup_problem(contest_id, problem_id, language)
|
|||
contest_id,
|
||||
problem_id
|
||||
),
|
||||
vim.log.levels.WARN
|
||||
vim.log.levels.INFO,
|
||||
true
|
||||
)
|
||||
|
||||
local scrape_result = scrape.scrape_problem(ctx)
|
||||
|
|
|
|||
|
|
@ -6,9 +6,9 @@ function M.set_config(user_config)
|
|||
config = user_config
|
||||
end
|
||||
|
||||
function M.log(msg, level)
|
||||
function M.log(msg, level, override)
|
||||
level = level or vim.log.levels.INFO
|
||||
if not config or config.debug or level >= vim.log.levels.WARN then
|
||||
if not config or config.debug or level >= vim.log.levels.WARN or override then
|
||||
vim.notify(('[cp.nvim]: %s'):format(msg), level)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -51,7 +51,8 @@ local function get_contests_for_platform(platform)
|
|||
local platform_display_name = constants.PLATFORM_DISPLAY_NAMES[platform] or platform
|
||||
logger.log(
|
||||
('Scraping %s for contests, this may take a few seconds...'):format(platform_display_name),
|
||||
vim.log.levels.WARN
|
||||
vim.log.levels.INFO,
|
||||
true
|
||||
)
|
||||
|
||||
local plugin_path = utils.get_plugin_path()
|
||||
|
|
@ -125,7 +126,8 @@ local function get_problems_for_contest(platform, contest_id)
|
|||
platform_display_name,
|
||||
contest_id
|
||||
),
|
||||
vim.log.levels.WARN
|
||||
vim.log.levels.INFO,
|
||||
true
|
||||
)
|
||||
|
||||
local metadata_result = scrape.scrape_contest_metadata(platform, contest_id)
|
||||
|
|
|
|||
|
|
@ -68,6 +68,22 @@ describe('cp.picker', function()
|
|||
end)
|
||||
|
||||
it('returns contest list when scraper succeeds', function()
|
||||
local cache = require('cp.cache')
|
||||
local utils = require('cp.utils')
|
||||
|
||||
cache.load = function() end
|
||||
cache.get_contest_list = function()
|
||||
return nil
|
||||
end
|
||||
cache.set_contest_list = function() end
|
||||
|
||||
utils.setup_python_env = function()
|
||||
return true
|
||||
end
|
||||
utils.get_plugin_path = function()
|
||||
return '/test/path'
|
||||
end
|
||||
|
||||
vim.system = function(_, _)
|
||||
return {
|
||||
wait = function()
|
||||
|
|
|
|||
|
|
@ -129,10 +129,37 @@ describe('cp.scrape', function()
|
|||
|
||||
describe('system dependency checks', function()
|
||||
it('handles missing uv executable', function()
|
||||
local cache = require('cp.cache')
|
||||
local utils = require('cp.utils')
|
||||
|
||||
cache.load = function() end
|
||||
cache.get_contest_data = function()
|
||||
return nil
|
||||
end
|
||||
|
||||
vim.fn.executable = function(cmd)
|
||||
return cmd == 'uv' and 0 or 1
|
||||
end
|
||||
|
||||
utils.setup_python_env = function()
|
||||
return vim.fn.executable('uv') == 1
|
||||
end
|
||||
|
||||
vim.system = function(cmd)
|
||||
if cmd[1] == 'ping' then
|
||||
return {
|
||||
wait = function()
|
||||
return { code = 0 }
|
||||
end,
|
||||
}
|
||||
end
|
||||
return {
|
||||
wait = function()
|
||||
return { code = 0 }
|
||||
end,
|
||||
}
|
||||
end
|
||||
|
||||
local result = scrape.scrape_contest_metadata('atcoder', 'abc123')
|
||||
|
||||
assert.is_false(result.success)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue