Skip to content

Commit

Permalink
Add tests for Context
Browse files Browse the repository at this point in the history
use pytest fixtures for parser.
  • Loading branch information
jurraca committed Jan 11, 2025
1 parent b67d92b commit 1236284
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions tests/test_context.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import os
import pytest
from kartograf.context import Context
from kartograf.cli import create_parser

@pytest.fixture(name="parser")
def fixture_parser():
return create_parser()

def test_basic_map_context(parser, tmp_path):
args = parser.parse_args(['map'])
os.chdir(tmp_path) # Use temporary directory
context = Context(args)

assert context.args.command == 'map'
assert context.reproduce is False
assert context.args.debug is True
assert context.args.cleanup is False
assert context.args.irr is False
assert context.args.routeviews is False
assert isinstance(context.epoch, str)
assert isinstance(int(context.epoch), int)
assert context.max_encode == 33521664
assert context.debug_log.endswith('debug.log')

def test_map_context_with_reproduce(parser, tmp_path):
# Setup a mock reproduction directory
repro_path = tmp_path / "repro"
repro_path.mkdir()
(repro_path / "irr").mkdir()
(repro_path / "collectors").mkdir()

args = parser.parse_args(['map', '-r', str(repro_path), '-t', '1225411200'])
context = Context(args)

assert context.reproduce is True
assert context.epoch == '1225411200'
assert context.epoch_dir == 'r1225411200'
assert context.args.irr is True # Should be True since irr dir exists
assert context.args.routeviews is True # Should be True since collectors dir exists

def test_map_context_with_wait(parser, tmp_path):
args = parser.parse_args(['map', '-w', '1225411200'])
os.chdir(tmp_path)
context = Context(args)

assert context.epoch == '1225411200'
assert context.epoch_dir == '1225411200'
assert not context.reproduce

def test_directory_creation(parser, tmp_path):
args = parser.parse_args(['map', '-irr', '-rv'])
os.chdir(tmp_path)
context = Context(args)

assert os.path.exists(context.data_dir_rpki_cache)
assert os.path.exists(context.data_dir_rpki_tals)
assert os.path.exists(context.data_dir_irr)
assert os.path.exists(context.data_dir_collectors)
assert os.path.exists(context.out_dir_rpki)
assert os.path.exists(context.out_dir_irr)
assert os.path.exists(context.out_dir_collectors)

0 comments on commit 1236284

Please sign in to comment.