kattis-cli 1.0.4__tar.gz → 1.0.6__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: kattis-cli
3
- Version: 1.0.4
3
+ Version: 1.0.6
4
4
  Summary: A command-line tool for Kattis
5
5
  Home-page: https://github.com/rambasnet/kattis-cli
6
6
  Author: Ram Basnet
@@ -108,6 +108,7 @@ kattis setup
108
108
  ```bash
109
109
  kattis <command> [options]
110
110
  kattis --help
111
+ kattis tui # get into text user interface mode
111
112
  ```
112
113
 
113
114
  ### Commands
@@ -82,6 +82,7 @@ kattis setup
82
82
  ```bash
83
83
  kattis <command> [options]
84
84
  kattis --help
85
+ kattis tui # get into text user interface mode
85
86
  ```
86
87
 
87
88
  ### Commands
@@ -7,13 +7,14 @@ build.sh script copies the contents of this file to main.py.
7
7
  Change the __version__ to match in pyproject.toml
8
8
  Has to be higher than the pypi version.
9
9
  """
10
- __version__ = '1.0.4'
10
+ __version__ = '1.0.6'
11
11
 
12
12
  from math import inf
13
13
  from typing import Tuple
14
14
  from rich.console import Console
15
15
  import click
16
16
  import requests
17
+ from trogon import tui
17
18
  import kattis_cli.download as download
18
19
  import kattis_cli.ui as ui
19
20
  import kattis_cli.test_solution as test_solution
@@ -22,6 +23,7 @@ import kattis_cli.utils.languages as languages
22
23
  import kattis_cli.kattis_setup as kattis_setup
23
24
 
24
25
 
26
+ @tui()
25
27
  @click.group()
26
28
  @click.version_option(version=__version__, prog_name='kattis-cli')
27
29
  def main() -> None:
@@ -2,6 +2,7 @@
2
2
  """
3
3
 
4
4
  from typing import Any, List, Dict
5
+ from math import inf
5
6
  import glob
6
7
  import time
7
8
  import os
@@ -26,7 +27,7 @@ def test_samples(
26
27
  problem_root_folder: str,
27
28
  files: List[str],
28
29
  lang_config: Dict[Any, Any],
29
- accuracy: float = 0
30
+ accuracy: float = inf
30
31
  ) -> None:
31
32
  """Tests a problem by running all the .in files in
32
33
  the problem folder and comparing the output to the .ans files.
@@ -118,28 +119,31 @@ def test_samples(
118
119
  input_content = f.read()
119
120
  input_content.replace(b'\r\n', b'\n') # Windows fix
120
121
  out_file = in_file.replace('.in', '.ans')
121
- with open(out_file, 'rb') as f:
122
- expected = f.read()
123
- expected.replace(b'\r\n', b'\n')
122
+ try:
123
+ with open(out_file, 'rb') as f:
124
+ expected = f.read()
125
+ expected.replace(b'\r\n', b'\n')
126
+ except FileNotFoundError:
127
+ try:
128
+ out_file = in_file.replace('.in', '.out')
129
+ with open(out_file, 'rb') as f:
130
+ expected = f.read()
131
+ expected.replace(b'\r\n', b'\n')
132
+ except FileNotFoundError:
133
+ expected = b"No .ans or .out file found!"
124
134
  # Run the program
125
135
  code, ans, error = run_program.run(lang_config, mainclass, in_file)
126
- expected = expected.strip()
127
136
  if code != 0:
128
137
  ans = error
129
138
  # console.print(f"{ans=} {error=}")
130
- if accuracy == 0: # string comparison
131
- if expected == ans.encode('utf-8').strip():
132
- result = "[bold green]✅[/bold green]"
133
- count += 1
134
- else:
135
- result = "[bold red]❌[/bold red]"
136
- else: # floating point comparison
137
- if utility.compare_floats(expected.decode('utf-8'),
138
- ans, accuracy):
139
- result = "[bold green]✅[/bold green]"
140
- count += 1
141
- else:
142
- result = "[bold red]❌[/bold red]"
139
+
140
+ # floating point comparison
141
+ if utility.check_answer(expected.decode('utf-8'),
142
+ ans, accuracy):
143
+ result = "[bold green]✅[/bold green]"
144
+ count += 1
145
+ else:
146
+ result = "[bold red]❌[/bold red]"
143
147
 
144
148
  # UI Table Row ---
145
149
  in_filename = Path(in_file).parts[-1]
@@ -2,6 +2,7 @@
2
2
 
3
3
  from pathlib import Path
4
4
  import os
5
+ from math import inf
5
6
  from typing import Union
6
7
  import yaml
7
8
 
@@ -60,21 +61,28 @@ def find_problem_root_folder(
60
61
  raise FileNotFoundError("Error: Problem root folder not found.")
61
62
 
62
63
 
63
- def compare_floats(expected: str, ans: str, places: float) -> bool:
64
- """Compare two floating point numbers with given accuracy.
64
+ def check_answer(expected: str, ans: str, places: float = inf) -> bool:
65
+ """Compare two numeric strings with given precision.
65
66
 
66
67
  Args:
67
68
  expected (str): expected result
68
69
  ans (str): actual result
69
- places (float): decimal places for approximation
70
+ places (float): decimal places for approximation;
71
+ default inf for string comparison
70
72
 
71
73
  Returns:
72
- bool: True if the two numbers are equal within the given accuracy
74
+ bool: True if the two values are equal, False otherwise
73
75
  """
74
76
  expect_ans = expected.strip().split('\n')
75
77
  actual_ans = ans.strip().split('\n')
76
78
  if len(expect_ans) != len(actual_ans):
77
79
  return False
80
+
81
+ if places == inf:
82
+ if expect_ans == actual_ans:
83
+ return True
84
+ else:
85
+ return False
78
86
  try:
79
87
  for i, ex_ans in enumerate(expect_ans):
80
88
  flt_expected = float(ex_ans)
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "kattis-cli"
3
- version = "1.0.4"
3
+ version = "1.0.6"
4
4
  authors = ["Ram Basnet <rbasnet@coloradomesa.edu>"]
5
5
  description = "A command-line tool for Kattis"
6
6
  readme = "README.md"
File without changes
File without changes